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

Replace Requests http client by Niquests and add built-in async support #186

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Ousret
Copy link

@Ousret Ousret commented Oct 23, 2024

This PR effectively replace the http client Requests for Niquests.
Niquests is a drop-in replacement for Requests that is no longer under feature freeze.

This new client support HTTP/2, and HTTP/3 by default and offers both sync and async interfaces. It supports all the latest shiny features you would expect from an http client.

If you were interested on merging, I will be interested to propose a followup PR that will propose a script that generate
the async part of prawcore automatically. If you want to.

Why make the switch?

I believe this will benefit you and your users:

  • Lower burden on maintaining library by having both sync/async in a single core package with a single code base.
  • Faster HTTP, multiplexed connection, HTTP/3 ready, etc..

disclaimer: I maintain Niquests.

@Ousret
Copy link
Author

Ousret commented Oct 23, 2024

We need to be able to pass PYTEST_DISABLE_PLUGIN_AUTOLOAD to the environment. Currently GH disallow doing this with reusable workflow.

@bboe
Copy link
Member

bboe commented Oct 23, 2024

This PR will take some thought as this is the first I've heard of Niquests. I'm generally a little weary of pulling in new packages, especially ones owned by individuals. I have a few questions: How many people have admin access to the repo, and what governs them? Who all can publish packages?

@LilSpazJoekp
Copy link
Member

Same concerns that @bboe has.

From a technical standpoint, PRAW will also need to pass all of its tests with this as well. It's unlikely we will switch http clients unless our concerns are resolved and it makes maintaining the async version significantly easier. The async changes to PRAW would also need to be a drop in replacement for Async PRAW.

@Ousret
Copy link
Author

Ousret commented Oct 23, 2024

Hello there,

Thanks for your fast response.

This PR will take some thought as this is the first I've heard of Niquests.

Naturally.

I have a few questions: How many people have admin access to the repo, and what governs them? Who all can publish packages?

  • Today, only my wife and I retain admin access. The roles are as follow, I develop, she manage the schedule, sponsors, fiscal, etc... Moreover, we have instructions left in case of "issues" left to each other so that the projects will be passed to a capable developer.
  • Only me can publish today.

We partnered up with Tidelift to ensure a source of income, also they handle the security part. They are reliable enough.
At current speed of thing, we reasonably expect mid-2025 to have enough Subscriber at Tidelift so that we can invite someone and share incomes. The plan is to reach 4 maintainers at Jawah (org) compensated with Tidelift. With this, we have in mind to offer bounties to freelancer every now and then.

We have gain enough trust (I hope) by managing project like charset-normalizer for example.

If we partner up on this, we will be able to move closer to the said goals.

It's unlikely we will switch http clients unless our concerns are resolved and it makes maintaining the async version significantly easier.

Maintaining the async part will be completely automatic after this PR. If you are willing to pursue this, I will manage a follow up PR that automatically generate this part like I have done in https://github.com/grafana-toolbox/grafana-client/blob/main/script/generate_async.py

I am sure that this will make your life easier, and additionally be of service to the broader community.

The async changes to PRAW would also need to be a drop in replacement for Async PRAW.

I will look into it, but it should be.

Regards,

@Ousret Ousret force-pushed the feat-niquests branch 2 times, most recently from c60e91e to 9d14800 Compare October 24, 2024 05:51
.coveragerc Outdated Show resolved Hide resolved
prawcore/requestor.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@LilSpazJoekp
Copy link
Member

We'll need to see if PRAW works with this (all tests pass) before proceeding as well.

@Ousret
Copy link
Author

Ousret commented Nov 6, 2024

Do you need anything else from my part?

regards,

@LilSpazJoekp
Copy link
Member

Would like to see it work with the async side of PRAW:

  • The generation of the async code
  • Works with exisiting Async PRAW code

@Ousret
Copy link
Author

Ousret commented Nov 10, 2024

Works with exisiting Async PRAW code

Done. praw-dev/asyncpraw#289

The generation of the async code

As I already stated, generating the async code AND the async tests are really challenging as per the 100% coverage constraint. I can generate the async code using a script, for sure, but I am less confident about the test suite to be generated along. Moreover, the async generation script is going to be doable in prawcore, not in praw or asyncpraw (due to the feature diff, asyncpraw isn't ISO with praw). In the long term, you could deprecate asyncpraw and generate the async part in praw instead.

I definitely want to propose another PR, dedicated to the async generation so that I can solely focus on it.

The work done in the three PRs should be a good starter point. WDYT?

Regards,

@Ousret
Copy link
Author

Ousret commented Nov 14, 2024

I updated praw to do the same as asyncpraw regarding websocket.
The projects are now closer than ever.

I will wait for further instruction & reviews from your side.

regards,

@LilSpazJoekp
Copy link
Member

This definitely looks promising! Give me time to review all the changes and discuss with @bboe about moving forward with this. I would like to see how the scripts to generate the async parts as that what will make this migration worthwhile.

@Ousret
Copy link
Author

Ousret commented Nov 19, 2024

Hello again,

I have just pushed an "experimental" async code generator in tools/

python tools/generate_async.py --help

usage: generate_async.py [-h] [-v] [-f] [-s] [-a]

Asynchronous Code Generator for PRAW

options:
  -h, --help        show this help message and exit
  -v, --verbose     Enable DEBUG logging
  -f, --fix         Applies the newer version of generated modules
  -s, --sync-diff   Render the differences between the synchronous parts and the newly generated asynchronous ones
  -a, --async-diff  Render the differences between the old async and newest async generated modules

It is not completed as we speak. But very close to be.

I am proposing this preview so that you can decide whether you (maintainers) want to pursue this integration (aka. async generation) or not.
So that I don't spend more time on it if it is not something you'd agree to.

I am waiting for your appreciations and feedback if any.

Regards,

@Ousret
Copy link
Author

Ousret commented Nov 20, 2024

The generator is complete for prawcore & integrated smoothly in pre-commit.
This project is one of the very few having this.

@LilSpazJoekp
Copy link
Member

Thanks for doing that! Give me some time to review this.

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.

3 participants