Skip to content

Conversation

@zeke
Copy link
Member

@zeke zeke commented Oct 6, 2025

This PR adds deprecated support for replicate.stream() as a wrapper around replicate.use() with streaming=True to provide backwards compatibility with the v1 SDK.

Changes

  • Add stream() methods to Replicate and AsyncReplicate classes with @deprecated decorators
  • Add module-level stream() function for replicate.stream() usage
  • Implement wrapper in src/replicate/lib/_stream.py that calls use() with streaming=True
  • Log detailed deprecation warnings with migration examples showing exact input parameters
  • Add comprehensive tests verifying deprecation warnings and behavior equivalence with use()
  • Update README to recommend replicate.use() with streaming=True as primary approach
  • Use anthropic/claude-4.5-sonnet in all examples

Add deprecated replicate.stream() method as a wrapper around
replicate.use() with streaming=True to provide backwards compatibility
with the v1 SDK.

- Add stream() methods to Replicate and AsyncReplicate classes
- Add module-level stream() function
- Use @deprecated decorator with clear migration message
- Add detailed deprecation warning with example code
- Add comprehensive tests for sync, async, and deprecation warnings
- Update README to recommend replicate.use() with streaming=True
- Use anthropic/claude-4.5-sonnet in all examples

Resolves: DP-671
@zeke zeke requested a review from a team as a code owner October 6, 2025 20:48
@linear
Copy link

linear bot commented Oct 6, 2025

DP-671 Add (deprecated) support for `replicate.stream()` in the v2 Python SDK

The legacy 1.x Python client supports a method called replicate.stream():

for event in replicate.stream(
    "anthropic/claude-4.5-sonnet",
    input={
        "prompt": "Give me a recipe for tasty smashed avocado on sourdough toast that could feed all of California.",
    },
):
    print(str(event), end="")

Docs about streaming are here: https://replicate.com/docs/topics/predictions/streaming

Tasks:

  • Implement replicate.stream() in the Stainless Python SDK
  • Make it a wrapper around the existing replicate.use(model, streaming:True) method without adding any more new code than necessary.
  • Log a deprecation message whenever replicate.stream() is invoked to let users know that replicate.stream() is deprecated, and that they should use replicate.use() instead, with streaming:True enabled. Make the log message include an example method call that works with the inputs they've provided.
  • Use Python's deprecated decorator if appropriate: https://typing.python.org/en/latest/spec/directives.html#deprecated
  • Add tests that:
    • verify replicate.stream() works
    • verify that it works that same way as replicate.use()
    • verify that it logs a deprecation message
  • Briefly allude to the existence of the replicate.stream() method in the README, but make it clear that it's deprecated in favor of replicate.use()

@zeke zeke changed the title feat: add deprecated replicate.stream() for v1 compatibility feat: add deprecated replicate.stream() for v1 compatibility Oct 6, 2025
@zeke zeke requested review from dgellow and removed request for dgellow October 6, 2025 21:36
@zeke zeke force-pushed the dp-671-add-deprecated-support-for-replicatestream-in-the-v2-python branch from bc09010 to 9b9d6b9 Compare October 6, 2025 21:45
@zeke zeke changed the base branch from next to main October 6, 2025 21:45
@zeke zeke marked this pull request as ready for review October 6, 2025 21:56
@zeke zeke requested a review from dgellow October 6, 2025 21:56
Comment on lines 84 to 85
Raises:
DeprecationWarning: Always raised when this function is called
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's wrong, no? We don't seem to raise an exception here, only log a warning message from what I can see 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed in 1f036c8 - removed the incorrect Raises section since we only issue a warning, not raise an exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝🏼 Hey, real Zeke here. Claude wrote that comment. I think this is the first time I've seen Claude Code successfully comment inline on a PR review!

I think it was this prompting: https://github.com/zeke/dotfiles/blob/e0277d51382eb08713b7181da6a4ef7ee4969424/.claude/CLAUDE.md#L19-L23

@dgellow
Copy link
Collaborator

dgellow commented Oct 9, 2025

The docstring looks wrong, but the rest looks all good to me 👍

The stream() function issues a deprecation warning via warnings.warn()
but doesn't raise an exception, so the Raises section was incorrect.
@zeke zeke merged commit 79b69bd into main Oct 10, 2025
11 checks passed
@zeke zeke deleted the dp-671-add-deprecated-support-for-replicatestream-in-the-v2-python branch October 10, 2025 16:38
This was referenced Oct 10, 2025
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