Leonardo.ai Python API
Project description
Leonardo_api
pypi package can be found here.
This is Leonardo.ai API.
This package contains Python API for Leonardo.ai based on official API documentation.
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:
```json
{'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 = await 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for leonardo_api-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 765e916786d8747e5ae54e8afa32ef86864791999a57c47c983551f6d1c5f19a |
|
MD5 | f4e5f852bd2baeab98f181707318955b |
|
BLAKE2b-256 | 60c0307266b135a23d1e868e204d4e0e8d933eac240cd200fb4b0f27e694fe4b |