Skip to content

Make importing and instantiating the client work the same way as before #12

Description

@zeke

This should work in the new client, for consistency with the legacy client:

import replicate

This doesn't necessarily have to be the default or only way to import and instantiate, but it should continue to work for feature parity, and to minimize code changes for users upgrading.

Tasks

Activity

  1. RobertCraigie commented on May 7, 2025

    @RobertCraigie
    Collaborator

    @zeke this should already work! see references to the "module client" https://github.com/replicate/replicate-python-stainless/blob/84a6a427de6be2d49f8ae5a165576be19d1bb4d1/src/replicate/_module_client.py#L70

    import replicate
    
    replicate.models.create(...)
  2. zeke commented on May 7, 2025

    @zeke
    MemberAuthor

    How do we update these docs?

    Image

  3. zeke commented on May 12, 2025

    @zeke
    MemberAuthor

    One useful way we can test this besides combing documentation is to actually swap out the client in some existing codebases and see if everything still works.

    Here are some examples: https://replicate.com/docs/reference/open-source#demo-apps

  4. zeke commented on Jun 9, 2025

    @zeke
    MemberAuthor

    Bump @dgellow @RobertCraigie

    See https://github.com/replicate/replicate-typescript-stainless/issues/8 for context on the changes made in the TypeScript SDK.

  5. RobertCraigie commented on Jun 10, 2025

    @RobertCraigie
    Collaborator

    While it isn't quite the same as your existing snippets yet, we did add b320609 (sorry for the bad commit message).

  6. dgellow commented on Jun 10, 2025

    @dgellow
    Collaborator

    Though, while the examples are now using replicate = instead of client =, the import will still be from replicate import Replicate. And not the simplified import replicate Zeke mentioned initially.

    Robert will correct me if I'm wrong here, but I do not believe that we currently have plans to support generating import <python project>, it's a bit too niche of a use case.

    @zeke Given that you mentioned it is ok for import replicate to not be the default, should we consider this issue to be completed now that we generate replicate = for all examples?

  7. self-assigned this
    on Jun 10, 2025
  8. zeke commented on Jun 11, 2025

    @zeke
    MemberAuthor

    I understand it's niche, but this is so much leaner:

    import replicate
    
    replicate.models.create(
        hardware="cpu",
        name="hot-dog-detector",
        owner="alice",
        visibility="public",
    )

    Than this:

    import os
    from replicate import Replicate
    
    replicate = Replicate(
        bearer_token=os.environ.get("REPLICATE_API_TOKEN"),  # This is the default and can be omitted
    )
    replicate.models.create(
        hardware="cpu",
        name="hot-dog-detector",
        owner="alice",
        visibility="public",
    )

    I wonder if there is some creative way we can pull this off... 🤔

  9. zeke commented on Jul 3, 2025

    @zeke
    MemberAuthor

    Note: The shorter code above actually works!

    It's just a matter of making it show up in the documentation that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions