This is Leonardo.ai API.
This package contains Python API for Leonardo.ai based on official API documentation.
To install the package, please use package from pypi:
pip install leonardo-api
This Python API provides access to Leonardo API using synchronous methods (based on requests library) as well as asynchronous (aiohttp). You can choose one of them - Leonardo or LeonardoAsync.
To start, you must have paid subscription and create an API access token from you settings page->User API. Then, init manager class with using your access_token:
from leonardo_api import Leonardo
leonardo = Leonardo(auth_token='abcd-1234-5678-90ef-deadbeef00000')
Now you can use all API methods, provided by Leonardo.ai API, i.e. starting getting user info and generating your first image:
response = leonardo.get_user_info() # get your user info
response = leonardo.post_generations(prompt="The quick brown fox jumps over the lazy dog", num_images=1,
negative_prompt='schrodinger cat paradox',
model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768,
guidance_scale=7)
In according to API reference, you will get the json answer with content about pending job like following:
{"sdGenerationJob": {"generationId": "123456-0987-aaaa-bbbb-01010101010"}}
To obtain your image you need to use additional method:
response = leonardo.get_single_generation(generation_id) # get it using response['sdGenerationJob']['generationId']
Or, optionally, you may wait for job completion using following method:
response = leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId'])
Finally, you'll get your array of images:
[{'url': 'https://cdn.leonardo.ai/users/abcd-1234-5678-90ef-deadbeef00000/generations/123456-0987-aaaa-bbbb-01010101010/Absolute_Reality_v16_The_quick_brown_fox_jumps_0.jpg', 'nsfw': False, 'id': 'aaaaaa-bbbb-cccc-dddd-ffffffffff', 'likeCount': 0, 'generated_image_variation_generics': []}]
You'll find descriptions for rest of the methods in official API reference.
As option, you may want to use preloaded dicts with models (nsfw/community/platform):
from leonardo_api import platform_models, custom_models, nsfw_models
Which contains details of models like following:
{
"data": {
"custom_models": [
{
"id": "f1929ea3-b169-4c18-a16c-5d58b4292c69",
"name": "RPG v5",
# rest of the model data
}
# rest models
]
}
}
Have fun and enjoy!
Donations
If you like this project, you can support it by donating via DonationAlerts or BuyMeACoffee or ThanksDev.
Metadata
Release files for leonardo-api 0.0.14
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 |
|---|---|---|---|---|
| leonardo_api-0.0.14.tar.gz | 807.2 kB | Without provenance | Details for leonardo_api-0.0.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| leonardo_api-0.0.14-py3-none-any.whl | Python 3 | none | any | Details for leonardo_api-0.0.14-py3-none-any.whl |
Total release size: 855.8 kB
Release files / leonardo_api-0.0.14.tar.gz
| Download URL | leonardo_api-0.0.14.tar.gz |
|---|---|
| Size | 807.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70cb299b7060ffc89e0947fdbfac65c8f06329b654ecc30b1b71981f4ca46fa1
|
|
BLAKE2b-256 checksum How to use checksums |
74a622cad52b96829f4d8a61acb874c97afca60ff5075828f012dde46765c94e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Release files / leonardo_api-0.0.14-py3-none-any.whl
| Download URL | leonardo_api-0.0.14-py3-none-any.whl |
|---|---|
| Size | 48.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f77972f2be875b3f5fd1a5660192a7b7fe3d7a1acb254620b3ab042277ae43de
|
|
BLAKE2b-256 checksum How to use checksums |
7a0688fbd0191b46f74c7a5ebcf5cee8140abc5e16140fd0066eac9597acbd9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Security for leonardo-api 0.0.14
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.