Replicate

Latest version: v1.0.3

Safety actively analyzes 681775 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 10

1.0.3

What's Changed
* Fix a bug where `replicate.run` would swallow tokens (or files) at the start of a prediction's output. Thanks to aron in https://github.com/replicate/replicate-python/pull/383

**Full Changelog**: https://github.com/replicate/replicate-python/compare/1.0.2...1.0.3

1.0.2

What's Changed
* Configure read timeout based on `wait` parameter by aron in https://github.com/replicate/replicate-python/pull/373

**Full Changelog**: https://github.com/replicate/replicate-python/compare/1.0.1...1.0.2

1.0.1

What's Changed
* 1.0.1 candidate by zeke in https://github.com/replicate/replicate-python/pull/368


**Full Changelog**: https://github.com/replicate/replicate-python/compare/1.0.0...1.0.1

1.0.0

> [!WARNING]
> **Breaking changes**

This 1.0.0 latest release of `replicate` contains breaking changes. The `replicate.run()` method will now return `FileObjects` rather than URL strings by default for models that output files.

The `FileObject` implements an iterable object similar to `httpx.Response` to make it easier to work with files and ensures that Replicate can deliver file data to the client in the most efficient manner possible.

For example:

py
[output] = replicate.run(
"black-forest-labs/flux-schnell",
input={"prompt": "astronaut riding a rocket like a horse"},
);


For most basic cases you'll want to utilize either the `url` or `read()` fields depending on whether you want to directly consume the file or pass it on.

To access the file URL:

python
print(output.url) => "https://delivery.replicate.com/..."


To consume the file directly:

python
with open('output.bin', 'wb') as file:
file.write(output.read())


Or for very large files they can be streamed:

python
with open(file_path, 'wb') as file:
for chunk in output:
file.write(chunk)


Each of these methods has an equivalent `asyncio` API.

python
async with aiofiles.open(filename, 'w') as file:
await file.write(await output.aread())

async with aiofiles.open(filename, 'w') as file:
await for chunk in output:
await file.write(chunk)


For streaming responses from common frameworks, all support taking `Iterator` types:

**Django**

python
condition(etag_func=None)
def stream_response(request):
output = replicate.run("black-forest-labs/flux-schnell", input={...}, use_file_output =True)
return HttpResponse(output, content_type='image/webp')


**FastAPI**

python
app.get("/")
async def main():
output = replicate.run("black-forest-labs/flux-schnell", input={...}, use_file_output =True)
return StreamingResponse(output)


**Flask**

python
app.route('/stream')
def streamed_response():
output = replicate.run("black-forest-labs/flux-schnell", input={...}, use_file_output =True)
return app.response_class(stream_with_context(output))


In case of breakages, in most instances, updating existing applications to call `output.url` should fix issues.

To revert to previous behaviour you can opt out of `FileOutput` by passing `use_file_output=False` to the `replicate.run()` method.

js
const replicate = replicate.run("acmecorp/acme-model", use_file_output=False);


**Full Changelog**: https://github.com/replicate/replicate-python/compare/0.34.2...1.0.0

0.34.1

What's Changed
* Consistently return Boolean for delete methods by mattt in https://github.com/replicate/replicate-python/pull/359


**Full Changelog**: https://github.com/replicate/replicate-python/compare/0.34.0...0.34.1

0.34.0

What's Changed
* Add `wait` parameter to prediction creation methods by mattt in https://github.com/replicate/replicate-python/pull/354
* Add `use_file_output` to streaming methods by mattt in https://github.com/replicate/replicate-python/pull/355


**Full Changelog**: https://github.com/replicate/replicate-python/compare/0.33.0...0.34.0

Page 1 of 10

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.