-
Notifications
You must be signed in to change notification settings - Fork 248
Add async support #193
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
Add async support #193
Conversation
Remove workaround of deleting version field from response JSON in _prepare_model Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
@@ -48,6 +49,7 @@ disable = [ | |||
"W0622", # Redefining built-in | |||
"R0903", # Too few public methods | |||
] | |||
good-names = ["id"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does good-names
mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're good names, Zeke.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(But seriously, this is to stop pylint from complaining about variables named id
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow this looks like it was a lot of work.
async variants with the
async_
prefix
Is this a cow-path convention in Python land for async variants of synchronous methods?
What are your thoughts on documenting these methods? Do something now or kick the can down the road until we have legit API reference docs for this client?
Add tests for calling async_run concurrently Signed-off-by: Mattt Zmuda <mattt@replicate.com>
@zeke Thanks for the review!
It sure was 🫠
As I understand it, yes. Another convention I've seen is prepending just The other (anti) pattern I've seen is to make it a separate package / module. So long as sync and async can coexist in
I added a callout towards the top of the README about methods having Footnotes
|
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
+1 Some libs use an |
@antont Interesting! Thank you for sharing that. The code base is at a manageable size now so that doing things manually isn't onerous, but I'll definitely want to set up automation like this once things get out of hand. |
This PR adds support for async operations to the Replicate client. Namespace operations like
predictions.list
andmodels.create
now have async variants with theasync_
prefix (predictions.async_list
andmodels.async_create
).Here's an example of what that looks like in practice:
Output
One of the most common questions I hear is how to run a bunch of predictions in parallel. The async functionality provided by this PR makes it really straightforward:
Under the hood,
Client
manages anhttpx.Client
and anhttpx.AsyncClient
, which handle calls to_request
and_async_request
, respectively. Both are created lazily, so API consumers using only sync or only async functionality won't be affected by functionality they aren't using.Implementation-wise, sync and async variants have separate code paths. This creates nontrivial amounts of duplication, but its benefits to clarity and performance justify those costs. For instance, it'd have been nice if the sync variant were implemented as a blocking call to the async variant, but that would require starting an event loop, which has additional overhead and causes problems if done within an existing event loop.
Alternative to #76
Resolves #145
Resolves #107
Resolves #74