pydalle: A DALL·E 2 API Wrapper for Python
This library provides basic programmatic access to the DALL·E 2 API.
The intent of this library is to provide researchers with a means to easily layout results from DALL·E 2 into a jupyter notebook or similar.
pydalle has two main modes of use:
pydalle.Dalle: This is the main class of the library. It provides a user-friendly interface to the DALL·E 2 API. Read more here.pydalle.imperative.api.labs: This module provides a set of lower-level functions that can be used to interact with the DALL·E 2 API. Read more here.
Installation
Install with all dependencies
pip install pydalle[all] # Install all dependencies, recommended for most users
Pick and choose your dependencies
pip install pydalle # Just install the library with no optional dependencies
pip install pydalle[sync] # Also installs requests (for synchronous networking)
pip install pydalle[async] # Also installs aiohttp and aiofiles (required for async networking / file handling)
pip install pydalle[images] # Also installs Pillow and numpy (required for help with image processing)
Tips
-
Get access by signing up for the DALL·E 2 waitlist.
-
Ensure your usage of DALL·E 2 abides by DALL·E 2's content policy and terms of use.
-
Be mindful about how easy this library makes it for you to spend your money / DALL·E 2 credits.
Getting Started
Once you have installed pydalle, you can start using it by importing it and creating a Dalle object.
You can find all the available methods on the Dalle class.
import os
from pydalle import Dalle
OPENAI_USERNAME = os.environ.get('OPENAI_USERNAME')
OPENAI_PASSWORD = os.environ.get('OPENAI_PASSWORD')
def main():
client = Dalle(OPENAI_USERNAME, OPENAI_PASSWORD)
print(f"Client created. {client.get_credit_summary().aggregate_credits} credits remaining...")
tasks = client.get_tasks(limit=5)
print(f"{len(tasks)} tasks found...")
print("Attempting to download a generation of the first task and show off some built-in helpers...")
if tasks and tasks[0].generations:
example = tasks[0].generations[0].download()
example.to_pil().show() # Convert the image to a PIL image and show it
example.to_pil_masked(x1=0.5, y1=0, x2=1, y2=1).show() # Show a version with left side transparent (for edits)
example.to_pil_padded(0.5).show() # Show w/ 50% padding around the image, centered at (50%, 50%)
example.to_pil_padded(0.4, cx=0.25, cy=0.25).show() # Show w/ 40% padding, centered at (25%, 25%)
print("Attempting to do a text2im task...")
completed_text2im_task = client.text2im("A cute cat")
for image in completed_text2im_task.download():
image.to_pil().show()
print("Attempting to create variations task on the first cat...")
first_generation = completed_text2im_task.generations[0]
completed_variation_task = first_generation.variations()
first_variation = completed_variation_task.generations[0]
first_image = first_variation.download()
first_image.to_pil().show()
print("Attempting to create inpainting task and showing the mask...")
# Make the right-side of the image transparent
mask = first_image.to_pil_masked(x1=0.5, y1=0, x2=1, y2=1)
mask.show("inpainting mask")
completed_inpainting_task = first_generation.inpainting("A cute cat, with a dark side", mask)
for image in completed_inpainting_task.download():
image.to_pil().show()
if __name__ == '__main__':
main()
For an equivalent async code example, see examples/dev_client_async.py.
For examples of the low-level API and using this in a notebook, see the examples/low_level directory.
Metadata
Release files for pydalle 0.2.0
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 |
|---|---|---|---|---|
| pydalle-0.2.0.tar.gz | 25.8 kB | Without provenance | Details for pydalle-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydalle-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pydalle-0.2.0-py3-none-any.whl |
Total release size: 57.6 kB
Release files / pydalle-0.2.0.tar.gz
| Download URL | pydalle-0.2.0.tar.gz |
|---|---|
| Size | 25.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef63a0ada8e9d44d8cdecefaee7efd89902ad92802e708fdcc838733de3b4d63
|
|
BLAKE2b-256 checksum How to use checksums |
f9840e1eddda7bac4380386734b00206cbe917d87faca9c124f77c60ebb6a695
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Release files / pydalle-0.2.0-py3-none-any.whl
| Download URL | pydalle-0.2.0-py3-none-any.whl |
|---|---|
| Size | 31.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3c2b80e0bffb787495e95e7c3f808c1a2dabf052af662ee7955a20068fe21d8
|
|
BLAKE2b-256 checksum How to use checksums |
ebd3b1dfae2f9416be887440ef7d630a0a8310e47ad2871f62d8dfead0d14f12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Security for pydalle 0.2.0
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.