Skip to content

Support orjson as an alternative encoder/decoder#1383

Draft
sirosen wants to merge 2 commits intoglobus:mainfrom
sirosen:define-orjson-encoder
Draft

Support orjson as an alternative encoder/decoder#1383
sirosen wants to merge 2 commits intoglobus:mainfrom
sirosen:define-orjson-encoder

Conversation

@sirosen
Copy link
Copy Markdown
Member

@sirosen sirosen commented May 4, 2026

Rebased onto #1384 to solve tox/ci config

Add support for user selection of orjson as a faster and more correct
JSON encoder/decoder. Request encoding is done by sending encoded bytes
through requests (which is supported), and request decoding is done
via a helper which reads requests.Response.content (bytes).

This is primarily applied in

  • the JSON request encoder
  • the Response class
  • the APIError base class

Additionally, GlobusApp and Transfer retry policies decode response
contents, and are here updated to load from bytes.

mypy runs are expanded to include orjson as a dependency, and
test runs include it via a factor.

New tests can directly target the encoder class, but as there is no
central point of control for decoding, there is no clearly testable
element for that purpose.

tox configuration and testing requirements are updated to pull in
orjson when the -orjson factor is used.
GitHub Actions testing is now expanded to include -orjson tests.

@sirosen sirosen force-pushed the define-orjson-encoder branch 3 times, most recently from 1dbcee8 to 76ff1fc Compare May 4, 2026 15:33
sirosen added 2 commits May 4, 2026 11:15
Previously, the test environments were binary flagged between `mindeps`
and `!mindeps`. This is unfortunately bad for adding additional factors,
as discovered when testing `orjson` as a factor. Because `tox` does not
allow negative factors to be layered with "OR" semantics, it becomes
difficult to deselect the locked requirements in `test.txt` in order
to replace them.

The base testenv is simplified to have unconditional dependencies, and
factor-based dependency selection is done in descendant envs which can
therefore fully replace the deps declared by the base env.

The change in configuration also provides an opportunity to refactor the
`depends` declaration into the list form which makes it inheritable.
Add support for user selection of `orjson` as a faster and more correct
JSON encoder/decoder. Request encoding is done by sending encoded bytes
through `requests` (which is supported), and request decoding is done
via a helper which reads `requests.Response.content` (bytes).

This is primarily applied in
- the JSON request encoder
- the Response class
- the APIError base class

Additionally, GlobusApp and Transfer retry policies decode response
contents, and are here updated to load from bytes.

`mypy` runs are expanded to include `orjson` as a dependency, and
test runs include it via a factor.

New tests can directly target the encoder class, but as there is no
central point of control for decoding, there is no clearly testable
element for that purpose.

tox configuration and testing requirements are updated to pull in
`orjson` when the `-orjson` factor is used.
GitHub Actions testing is now expanded to include `-orjson` tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant