Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Use httpx for the transport layer #1968

Open
devkral opened this issue Jan 22, 2024 · 6 comments
Open

[FEATURE] Use httpx for the transport layer #1968

devkral opened this issue Jan 22, 2024 · 6 comments
Assignees
Labels
Core: Transport Sending data to the tested app Priority: High Important but not urgent Type: Feature New functionalities or enhancements
Milestone

Comments

@devkral
Copy link
Contributor

devkral commented Jan 22, 2024

Is your feature request related to a problem? Please describe

Currently schemathesis uses requests. This has following drawbacks:

  • no real async/asgi, you need to write boilerplate code
  • the starlette test client switched to httpx, incompatibilities
  • requests development is stalled, so the incompatibilities will increase

I would recommend to migrate away from requests and can recommend httpx as alternative.
There are maybe some other nice libraries out there but httpx has two killer features:

  • calling asgi/wsgi directly, no need for boilerplate. No need for the Starlette TestClient for downloading the schema (uses httpx internally anyway)
  • async. Soon ASGI will be more common and it will become harder to test without async support

@Stranger6667:

Moving all the current transports to httpx will have the extra benefit of dropping starlette_test_client, werkzeug & requests. I hope all of them can be dropped and we can use just different httpx transports.

Also, the Schemathesis test runner will benefit from async execution of requests which will be simpler to implement as it will help with cancellation (i.e. httpbin's drip endpoint can hang schemathesis)

On the implementation side of things, the ASGI transport is async, but the main flow is sync, so we need an adapter to run those requests synchronously.

Such a change will likely happen with the 4.0 release.

@devkral devkral added Status: Needs Triage Requires initial assessment to categorize and prioritize Type: Feature New functionalities or enhancements labels Jan 22, 2024
@devkral
Copy link
Contributor Author

devkral commented Jan 22, 2024

and there seems to be a transition to httpx so your code would be more interoperable

@devkral
Copy link
Contributor Author

devkral commented Jan 22, 2024

everyone has his own library preferences ;). It is just my recommendation.

@Stranger6667
Copy link
Member

There is a long-running plan to switch to httpx (specifically in #1718 and previously discussed in some more issues) for multiple reasons, the main one for me is the cancellation in CLI.

While I agree with the reasoning you provided, I feel that this is more like a duplicate of #1718 that suggests providing multiple transports instead of a complete switch (it also will unblock alternative transports that could be something useful for future gRPC support). A complete switch would be backward-incompatible for many users who would be forced to switch to using httpx in their tests and with pluggable transports such a transition would be smoothened.

It is completely fine to switch rapidly for apps, but for a library on which many users rely on, I'd prefer to take a more flexible way.

As a side note, what kind of boilerplate did you mention? I am genuinely interested in reducing the amount of boilerplate, but I'd like to have some actionable inputs and clearly see how httpx will help to avoid it - it will also help me to provide a better API from the Schemathesis side for all users.

@Stranger6667
Copy link
Member

Now, I also see that #1718 lacks certain implementation details about the transport layer. I'm going to update it soon

@devkral
Copy link
Contributor Author

devkral commented Jan 22, 2024

thanks! And sorry for the duplicate

Found another frustrating bug: requests.Session is incompatible with asgi/wsgi

@devkral
Copy link
Contributor Author

devkral commented Jan 22, 2024

an idea:

you have the method get_requests_kwargs. Check if the class is requests.Session or httpx.Session and transform the arguments accordingly or remove if not supported.

This way httpx Session can be used by default (and the boilerplate code removed) and requests.Session only if explicitly specified (it doesn't supports wsgi/asgi calls anyway as far as I know)

@Stranger6667 Stranger6667 added Type: Feature New functionalities or enhancements Core: Transport Sending data to the tested app Priority: High Important but not urgent and removed Status: Needs Triage Requires initial assessment to categorize and prioritize Type: Feature New functionalities or enhancements labels Apr 8, 2024
@Stranger6667 Stranger6667 changed the title [FEATURE] simplify your code with httpx [FEATURE] Use httpx for the transport layer Apr 8, 2024
@Stranger6667 Stranger6667 added this to the 4.0 milestone Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core: Transport Sending data to the tested app Priority: High Important but not urgent Type: Feature New functionalities or enhancements
Projects
None yet
Development

No branches or pull requests

2 participants