Stability AI
An UNOFFICIAL client library for the stability.ai REST API.
Motivation
The official stability-sdk is a based on gRPC and also really hard to use. Like look at this, this
ignores setting up the SDK.
from stability_sdk import client
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
answers = stability_api.generate(
prompt="a rocket-ship launching from rolling greens with blue daisies",
seed=892226758,
steps=30,
cfg_scale=8.0,
width=512,
height=512,
sampler=generation.SAMPLER_K_DPMPP_2M
)
for resp in answers:
for artifact in resp.artifacts:
if artifact.finish_reason == generation.FILTER:
warnings.warn(
"Your request activated the API's safety filters and could not be processed."
"Please modify the prompt and try again.")
if artifact.type == generation.ARTIFACT_IMAGE:
global img
img = Image.open(io.BytesIO(artifact.binary))
img.save(str(artifact.seed)+ ".png")
This for loop is magic. You must loop the results in exactly this way or the gRPC library won't work. It's about an unpythonic as a library can get.
My Take
# Set the STABILITY_API_KEY environment variable.
from stabilityai.client import AsyncStabilityClient
from stabilityai.models import Sampler
async def example():
async with AsyncStabilityClient() as stability:
results = await stability.text_to_image(
text_prompt="a rocket-ship launching from rolling greens with blue daisies",
# All these are optional and have sane defaults.
seed=892226758,
steps=30,
cfg_scale=8.0,
width=512,
height=512,
sampler=Sampler.K_DPMPP_2M,
)
artifact = results.artifacts[0]
img = Image.open(artifact.file)
img.save(artifact.file.name)
Additional Nicetieis
-
Instead of manually checking
FINISH_REASONan appropriate exception will automatically be raised. -
Full mypy/pyright support for type checking and autocomplete.
Metadata
Release files for stabilityai 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stabilityai-1.0.5.tar.gz | 11.8 kB | Without provenance | Details for stabilityai-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stabilityai-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for stabilityai-1.0.5-py3-none-any.whl |
Total release size: 21.8 kB
Release files / stabilityai-1.0.5.tar.gz
| Download URL | stabilityai-1.0.5.tar.gz |
|---|---|
| Size | 11.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12ffb4ba2e39560b44a90d72734cd0f8d67ac6337b2c4e54acebb590f385e788
|
|
BLAKE2b-256 checksum How to use checksums |
a9f9d45dd0436945a2a4e4597c957d81198cb04eb6658721c8fcf5ae4bc845ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.8
|
Release files / stabilityai-1.0.5-py3-none-any.whl
| Download URL | stabilityai-1.0.5-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cda4eee6d57c4a70c6cde7a6cd74d5808f5f84ababcec10e93658ad16e635ff0
|
|
BLAKE2b-256 checksum How to use checksums |
88b0ca1b81c0c463af2a7a16f6e5d3c0d0259b2876aeb295a7f2b9ffc3592d40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.8
|
Security for stabilityai 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.