Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Imagine SDK

Imagine SDK is a Python library that provides a convenient interface to interact with the Imagine API for image generation and manipulation. This README provides an overview of the library's features, installation instructions, and usage examples.

Table of Contents

Installation

The API works for python 3.6 and above. To install the package, execute the following command:

pip install imaginesdk

Usage

The SDK needs to be configured with an API key which is available here. It will be passed to the Imagine class as an argument while instantiating it.

from imagine import Imagine
from imagine.styles import GenerationsStyle
from imagine.models import Status

# Initialize the Imagine client with your API token
client = Imagine(token="your-api-token")

# Generate an image using the generations feature
response = client.generations(
    prompt='''
    A vibrant and whimsical fantasy forest with magical creatures, glowing plants, 
    and a flowing river, in a digital painting style inspired by video games like Ori and the Blind Forest.
    ''',
    style=GenerationsStyle.IMAGINE_V5,
)

# Check if the request was successful
if response.status == Status.OK:
    image = response.data
    image.as_file("result.png")
else:
    print(f"Status Code: {response.status.value}")

Result:

Generations

Imagine Client

The Imagine class acts as a facade, providing an interface to interact with all of our endpoints. It currently provides the following features:

  • Text-To-Image: generations() -> Response[Image]
  • Image-Remix: image_remix() -> Response[Image]
  • Super-Resolution: super_resolution() -> Response[Image]
  • Variations: variations() -> Response[Image] (Currently Not Supported)
  • In-Painting: in_painting() -> Response[Image] (Currently Not Supported)

For the full list of parameters and other details, check out the documentation.

Response

Response is the return type for each of our functions. It contains the following:

  • status: Status property which returns an enum containing the status code of the response.
  • data: A property which contains the request response.
  • get_or_throw(): either returns the response content or raises an Error if the response content was empty.
  • get_or_else(): either returns the response content or returns the default value if its empty.

For the full list of arguments and other details, check out the documentation.

Image

All the functions related to Images contain an Image data type as the data in their Response. It currently provides the following:

bytes

Returns the bytes received after a request operation

image.bytes # -> bytes

as_file(file_path: str)

Stores the image in the specified path and returns the path.

image.as_file("file_path") # -> str (file_path)

to_pil_image()

The module is loaded dynamically and is not included in the default package, you can choose to forgo this dependency. See this for more information.

to_numpy()

The module is loaded dynamically and is not included in the default package, you can choose to forgo this dependency. See this for more information.

Some More Usage Examples

Variations

Currently Not Supported

from imagine import Imagine
from imagine.styles import GenerationsStyle
from imagine.models import Status

# Initialize the Imagine client with your API token
client = Imagine(token="your-api-token")

# Generate an image using the variations feature
response = client.variate(
    image_path="anime_girl.png",
    prompt="a cute anime girl in a forest",
    style=GenerationStyle.ANIME,
)

# Check if the request was successful
if response.status == Status.OK:
    image = response.data
    image.as_file("result.png")
else:
    print(f"Status Code: {response.status.value}")

Result:

Variate

In-Painting

Currently Not Supported

from imagine import Imagine
from imagine.styles import InPaintingStyle
from imagine.models import Status

# Initialize the Imagine client with your API token
client = Imagine(token="your-api-token")

# Generate an image using the in_painting feature
response = client.in_painting(
    image_path="couple.png",
    mask_path="mask.png",
    prompt="woman sitting next to a teddy bear",
    style=InPaintingStyle.BASIC,
)

# Check if the request was successful
if response.status == Status.OK:
    image = response.data
    image.as_file("result.png")
else:
    print(f"Status Code: {response.status.value}")

Result: InPainting

Integration With Other Libraries

The Imagine SDK has two levels of dependencies. By default, only the requests library is shipped as a dependency. If you want to use Pillow and Numpy as well, execute the following command:

pip install imaginesdk[all]

If you want one but not the other dependency then you also have the option of installing the module separately.

Pillow (PIL)

If you installed imaginesdk[all], you can skip the first step.

First, get the dependency for Pillow

pip install Pillow

After running the aforementioned command you can now use the response data as a pillow object:

image.to_pil_image() # -> PIL_Image

Numpy

If you installed imaginesdk[all], you can skip the first step.

First, get the dependency for Numpy

pip install numpy

After running the aformentioned command you can now use the response data as a numpy object:

image.to_numpy() # -> numpy.ndarray

Support

If you run into any version issues, please contact us at api.imagine@vyro.ai or support.imagine.api

License

This project is licensed under the Apache 2 License.

Metadata

Release files for imaginesdk 1.0.0b4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imaginesdk 1.0.0b4
File Size Uploaded Provenance Actions
imaginesdk-1.0.0b4.tar.gz 20.3 kB Without provenance Details for imaginesdk-1.0.0b4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for imaginesdk 1.0.0b4
File Interpreter ABI Platform Actions
imaginesdk-1.0.0b4-py3-none-any.whl Python 3 none any Details for imaginesdk-1.0.0b4-py3-none-any.whl

Total release size: 48.1 kB

Release files / imaginesdk-1.0.0b4.tar.gz

Download URL imaginesdk-1.0.0b4.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bbe411b8ee84b62ec1a5b22418d2e15c80ab24c2840b9bb3f1c65268e4a37b8e
BLAKE2b-256 checksum
How to use checksums
18c47506c0cd64937378373e61bca7d62a09c67edbcda9bcefcb5336c1b3468a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release files / imaginesdk-1.0.0b4-py3-none-any.whl

Download URL imaginesdk-1.0.0b4-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
764c0829c81d92a370a67cffa479a158f1cb60c633a7ade5ee8db5acd86db64e
BLAKE2b-256 checksum
How to use checksums
b937c60300c369d1998a7a69da84561c3a602381ae138a6478bb1fa60fa52272
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Security for imaginesdk 1.0.0b4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page