pydalle.imperative.client package
Submodules
A user-friendly interface for the low-level functional API of pydalle.
- class pydalle.imperative.client.dalle.Dalle(username: str, password: str, /, headers: Optional[dict] = None)
Bases:
objectA user-friendly interface for the low-level functional API of pydalle.
- create_inpainting_task(caption: str, masked_image: Union[WrappedImage, module, bytes, str], parent: Optional[Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt]] = None, batch_size: int = 3) WrappedTask
Creates an inpainting task.
- Parameters
caption – The caption to use.
masked_image – The masked image to use.
parent – The parent to use. (Either a prompt, a generation, or an image).
batch_size – The batch size to use.
- Returns
The task.
- async create_inpainting_task_async(caption: str, masked_image: Union[WrappedImage, module, bytes, str], parent: Optional[Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt]] = None, batch_size: int = 3) WrappedTask
Asynchronously creates an inpainting task.
- Parameters
caption – The caption to use.
masked_image – The masked image to use.
parent – The parent to use. (Either a prompt, a generation, or an image).
batch_size – The batch size to use.
- Returns
The task.
- create_text2im_task(caption: str, batch_size: int = 4) WrappedTask
Creates a text2im task.
- Parameters
caption – The caption to use.
batch_size – The batch size to use.
- Returns
The task.
- async create_text2im_task_async(caption: str, batch_size: int = 4) WrappedTask
Asynchronously creates a text2im task.
- Parameters
caption – The caption to use.
batch_size – The batch size to use.
- Returns
The task.
- create_variations_task(parent: Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt], batch_size: int = 3) WrappedTask
Creates a variations task.
- Parameters
parent – The parent to use. (Either a prompt, a generation, or an image).
batch_size – The batch size to use.
- Returns
The task.
- async create_variations_task_async(parent: Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt], batch_size: int = 3) WrappedTask
Asynchronously creates a variations task.
- Parameters
parent – The parent to use. (Either a prompt, a generation, or an image).
batch_size – The batch size to use.
- Returns
The task.
- download_generation(generation: Union[WrappedGeneration, Generation, str], direct: bool = False) WrappedImage
Downloads a generation.
- Parameters
generation – The generation to download.
direct – Whether to download the generation using the direct download URL, which does not add a watermark. You should only use this if you intend to add the watermark to the image yourself. Unwatermarked images should not be shared publicly.
- Returns
The image.
- async download_generation_async(generation: Union[WrappedGeneration, Generation, str], direct: bool = False) WrappedImage
Asynchronously downloads a generation.
- Parameters
generation – The generation to download.
direct – Whether to download the generation using the direct download URL, which does not add a watermark. You should only use this if you intend to add the watermark to the image yourself. Unwatermarked images should not be shared publicly.
- Returns
The image.
- download_generation_direct(generation: Union[WrappedGeneration, Generation, str]) WrappedImage
Downloads a generation using the direct download URL, which does not add a watermark. You should only use this if you intend to add the watermark to the image yourself. Unwatermarked images should not be shared publicly.
- Parameters
generation – The generation to download.
- Returns
The image.
- async download_generation_direct_async(generation: Union[WrappedGeneration, Generation, str]) WrappedImage
Asynchronously downloads a generation using the direct download URL, which does not add a watermark.
- Parameters
generation – The generation to download.
- Returns
The image.
- flag_generation_sensitive(generation: Union[WrappedGeneration, Generation, str]) WrappedUserFlag
Flags a generation as sensitive.
- Parameters
generation – The generation to flag.
- Returns
The user flag.
- async flag_generation_sensitive_async(generation: Union[WrappedGeneration, Generation, str]) WrappedUserFlag
Asynchronously flags a generation as sensitive.
- Parameters
generation – The generation to flag.
- Returns
The user flag.
- flag_generation_unexpected(generation: Union[WrappedGeneration, Generation, str]) WrappedUserFlag
Flags a generation as unexpected.
- Parameters
generation – The generation to flag.
- Returns
The user flag.
- async flag_generation_unexpected_async(generation: Union[WrappedGeneration, Generation, str]) WrappedUserFlag
Asynchronously flags a generation as unexpected.
- Parameters
generation – The generation to flag.
- Returns
The user flag.
- get_credit_summary() WrappedBillingInfo
Gets the user’s credit summary.
- Returns
The user’s credit summary.
- async get_credit_summary_async() WrappedBillingInfo
Asynchronously gets the user’s credit summary.
- Returns
The user’s credit summary.
- get_generation(generation: Union[WrappedGeneration, Generation, str]) WrappedGeneration
Gets a generation.
- Parameters
generation – The generation to get (either a generation ID or a generation object).
- Returns
The generation.
- async get_generation_async(generation: Union[WrappedGeneration, Generation, str]) WrappedGeneration
Asynchronously gets a generation.
- Parameters
generation – The generation to get (either a generation ID or a generation object).
- Returns
The generation.
- get_login_info() WrappedLogin
Gets the user’s login information.
- Returns
The user’s login information.
- async get_login_info_async() WrappedLogin
Asynchronously gets the user’s login information.
- Returns
The user’s login information.
- get_task(task: Union[WrappedTask, Task, str]) WrappedTask
Gets a task.
- Parameters
task – The task to get (either a task ID or a task object).
- Returns
The task.
- async get_task_async(task: Union[WrappedTask, Task, str]) WrappedTask
Asynchronously gets a task.
- Parameters
task – The task to get (either a task ID or a task object).
- Returns
The task.
- get_tasks(limit: Optional[int] = None, from_ts: Optional[int] = None) WrappedTaskList
Gets a list of tasks.
- Parameters
limit – The maximum number of tasks to return.
from_ts – The timestamp to start from.
- Returns
A list of tasks.
- async get_tasks_async(limit: Optional[int] = None, from_ts: Optional[int] = None) WrappedTaskList
Asynchronously a list of tasks.
- Parameters
limit – The maximum number of tasks to return.
from_ts – The timestamp to start from.
- Returns
A list of tasks.
- inpainting(caption: str, masked_image: Union[WrappedImage, module, bytes, str], parent: Optional[Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt]] = None, batch_size: int = 3, wait: bool = True) WrappedTask
Convenience function to create and wait an inpainting task.
- Parameters
caption – The caption to use.
masked_image – The masked image to use.
parent – The parent to use. (Either a prompt, a generation, or an image).
batch_size – The batch size to use.
wait – Whether to wait for the task to finish, default is True.
- Returns
The task.
- async inpainting_async(caption: str, masked_image: Union[WrappedImage, module, bytes, str], parent: Optional[Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt]] = None, batch_size: int = 3, wait: bool = True) WrappedTask
Asynchronously creates and waits for an inpainting task.
- Parameters
caption – The caption to use.
masked_image – The masked image to use.
parent – The parent to use. (Either a prompt, a generation, or an image).
batch_size – The batch size to use.
wait – Whether to wait for the task to finish, default is True.
- Returns
The task.
- poll_for_task_completion(task: Union[WrappedTask, Task, str], interval: float = 1.0, max_attempts: int = 1000) WrappedTask
Polls for the completion of a task.
- Parameters
task – The task to poll.
interval – The interval to use (in seconds).
max_attempts – The maximum number of attempts.
- async poll_for_task_completion_async(task: Union[WrappedTask, Task, str], interval: float = 1.0, max_attempts: int = 1000) WrappedTask
Asynchronously polls for the completion of a task.
- Parameters
task – The task to poll.
interval – The interval to use (in seconds).
max_attempts – The maximum number of attempts.
- refresh_tokens() None
Refreshes the access token and bearer token.
- async refresh_tokens_async() None
Asynchronously refreshes the access token and bearer token.
- save_generations(generations: Union[Iterable[Union[WrappedGeneration, Generation, str]], WrappedGeneration, Generation, str]) WrappedCollection
Saves one or more generations to your personal collection.
- Parameters
generations – The generation(s) to save.
- Returns
The collection saved to.
- async save_generations_async(generations: Union[Iterable[Union[WrappedGeneration, Generation, str]], WrappedGeneration, Generation, str]) WrappedCollection
Asynchronously saves one or more generations to your personal collection.
- Parameters
generations – The generation(s) to save.
- Returns
The collection saved to.
Shares a generation (i.e. people can then download the generation from the share URL). See DALL·E 2’s content policy to see what is OK to share.
- Parameters
generation – The generation to share.
- Returns
The shared generation.
Asynchronously shares a generation (i.e. people can then download the generation from the share URL). See DALL·E 2’s content policy to see what is OK to share.
- Parameters
generation – The generation to share.
- Returns
The shared generation.
- text2im(caption: str, batch_size: int = 4, wait: bool = True) WrappedTask
Convenience function to create and wait a text2im task.
- Parameters
caption – The caption to use.
batch_size – The batch size to use.
wait – Whether to wait for the task to finish, default is True.
- Returns
The task.
- async text2im_async(caption: str, batch_size: int = 4, wait: bool = True) WrappedTask
Asynchronously creates and waits for a text2im task.
- Parameters
caption – The caption to use.
batch_size – The batch size to use.
wait – Whether to wait for the task to finish, default is True.
- Returns
The task.
- variations(parent: Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt], batch_size: int = 3, wait: bool = True) WrappedTask
Convenience function to create and wait a variations task.
- Parameters
parent – The parent to use. (Either a prompt, a generation, or an image).
batch_size – The batch size to use.
wait – Whether to wait for the task to finish, default is True.
- Returns
The task.
- async variations_async(parent: Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt], batch_size: int = 3, wait: bool = True) WrappedTask
Asynchronously creates and waits for a variations task.
- Parameters
parent – The parent to use. (Either a prompt, a generation, or an image).
batch_size – The batch size to use.
wait – Whether to wait for the task to finish, default is True.
- Returns
The task.
- class pydalle.imperative.client.responses.WrappedBillingInfo(billing_info: BillingInfo, dalle: Dalle)
Bases:
WrappedResponse- property aggregate_credits: int
- property next_grant_ts: int
- wrapped: BillingInfo
- class pydalle.imperative.client.responses.WrappedCollection(collection: Collection, dalle: Dalle)
Bases:
WrappedResponse- property alias: str
- property created: int
- property description: str
- property id: str
- property is_public: bool
- property name: str
- wrapped: Collection
- class pydalle.imperative.client.responses.WrappedGeneration(generation: Generation, dalle: Dalle)
Bases:
WrappedResponse- property created: int
- property direct_image_path: str
- download(direct=False) WrappedImage
- async download_async(direct=False) WrappedImage
- property generation: GenerationData
- property generation_type: str
- property id: str
- inpainting(caption: str, masked_image: Union[WrappedImage, module, bytes, str], wait=True)
- async inpainting_async(caption: str, masked_image: Union[WrappedImage, module, bytes, str], wait=True)
- property is_public: bool
- property prompt_id: str
- property task_id: str
- variations(wait=True)
- async variations_async(wait=True)
- wrapped: Generation
- class pydalle.imperative.client.responses.WrappedGenerationList(generation_list: GenerationList, dalle: Dalle)
Bases:
object- wrapped: GenerationList
- class pydalle.imperative.client.responses.WrappedImage(image: bytes, dalle: Dalle, filetype: str = 'png')
Bases:
WrappedResponse- property png_bytes: bytes
- to_numpy() ndarray
Returns a numpy array for the image.
- Returns
A numpy array.
- to_pil() module
Returns a PIL image object for the image.
- Returns
A PIL image object.
- to_pil_masked(x1: float, y1: float, x2: float, y2: float) module
Returns a PIL image object for the image, with the given mask applied.
- Parameters
x1 – The percentage of the image on the left before the mask starts.
y1 – The percentage of the image on the top before the mask starts.
x2 – The percentage of the image on the right after the mask ends.
y2 – The percentage of the image on the bottom after the mask ends.
- Returns
A masked PIL image object.
- to_pil_padded(p: float, cx: float = 0.5, cy: float = 0.5) module
Returns a PIL image object for the image, with the given padding applied.
- Parameters
p – The percentage of the image to pad. E.g. 0.5 means the image will be shrunk by 50%.
cx – Where the newly shrunk image will be centered horizontally. Default is 0.5, the center.
cy – Where the newly shrunk image will be centered vertically. Default is 0.5, the center.
- Returns
A padded PIL image object.
- wrapped: bytes
- class pydalle.imperative.client.responses.WrappedLogin(login: Login, dalle: Dalle)
Bases:
WrappedResponse- property invites: List[Any]
- class pydalle.imperative.client.responses.WrappedResponse(wrapped: T, dalle: Dalle)
Bases:
objectGeneric wrapper for responses from the Dalle API. This has the following benefits:
- The dalle client is passed in as an argument to the constructor, so that the client can be used to
make requests related to the wrapped response.
Getters for attributes in the lower-level response helps protect against changes in the API.
- class pydalle.imperative.client.responses.WrappedTask(task: Task, dalle: Dalle)
Bases:
WrappedResponse- property created: int
- download(direct=False) Generator[WrappedImage, None, None]
- async download_async(direct=False) AsyncGenerator[WrappedImage, None]
- property generations: Optional[WrappedGenerationList]
- property id: str
- property pending: bool
- property prompt_id: str
- property rejected: bool
- property status: str
- property status_information: StatusInformation
- property succeeded: bool
- property task_type: Union[Literal['inpainting'], Literal['text2im'], Literal['variations']]
- wait() WrappedTask
- async wait_async() WrappedTask
- class pydalle.imperative.client.responses.WrappedTaskList(task_list: TaskList, dalle: Dalle)
Bases:
WrappedResponse
- class pydalle.imperative.client.responses.WrappedUserFlag(user_flag: UserFlag, dalle: Dalle)
Bases:
WrappedResponse- property created: int
- property description: str
- property generation_id: str
- property id: str
- pydalle.imperative.client.responses.get_generation_id(generation: Union[WrappedGeneration, Generation, str]) str
- pydalle.imperative.client.responses.get_image_png_base64(image: Union[WrappedImage, module, bytes, str], headers: Optional[dict]) str
- async pydalle.imperative.client.responses.get_image_png_base64_async(image: Union[WrappedImage, module, bytes, str], headers: Optional[dict] = None) str
- pydalle.imperative.client.responses.get_parent_id_or_png_base64(parent: Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt], headers: Optional[dict]) Union[str, bytes]
- async pydalle.imperative.client.responses.get_parent_id_or_png_base64_async(parent: Union[WrappedImage, module, bytes, str, WrappedGeneration, Generation, Prompt], headers: Optional[dict]) Union[str, bytes]
- pydalle.imperative.client.responses.get_task_id(task: Union[WrappedTask, Task, str]) str
- pydalle.imperative.client.utils.requires_authentication(func: T) T
Decorator to ensure that the Dalle has authenticated before calling the decorated function (or, if it has authenticated but the token has expired, it will refresh the tokens then try again).
- pydalle.imperative.client.utils.requires_authentication_async(func: T) T
Async version of the
requires_authentication()decorator.