{"id":19048480,"url":"https://github.com/wwakabobik/leonardo_api","last_synced_at":"2025-04-24T00:51:16.476Z","repository":{"id":191410917,"uuid":"684671666","full_name":"wwakabobik/leonardo_api","owner":"wwakabobik","description":"Leonardo.ai API","archived":false,"fork":false,"pushed_at":"2025-04-11T19:59:33.000Z","size":953,"stargazers_count":18,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T20:43:00.740Z","etag":null,"topics":["ai","api","async-api","leonardo","leonardo-ai","leonardo-api","python","python3","requests-apis"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/leonardo-api/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wwakabobik.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-29T16:08:31.000Z","updated_at":"2025-04-11T19:59:35.000Z","dependencies_parsed_at":"2023-10-16T06:26:50.883Z","dependency_job_id":"bcdef617-92ab-4e51-a4c7-936ef02af72c","html_url":"https://github.com/wwakabobik/leonardo_api","commit_stats":null,"previous_names":["wwakabobik/leonardo_api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwakabobik%2Fleonardo_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwakabobik%2Fleonardo_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwakabobik%2Fleonardo_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwakabobik%2Fleonardo_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wwakabobik","download_url":"https://codeload.github.com/wwakabobik/leonardo_api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250540956,"owners_count":21447426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api","async-api","leonardo","leonardo-ai","leonardo-api","python","python3","requests-apis"],"created_at":"2024-11-08T23:07:02.203Z","updated_at":"2025-04-24T00:51:16.438Z","avatar_url":"https://github.com/wwakabobik.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## This is Leonardo.ai API.\n\n[![PyPI version](https://badge.fury.io/py/leonardo-api.svg)](https://badge.fury.io/py/leonardo-api) \n[![Linters](https://github.com/wwakabobik/leonardo_api/actions/workflows/master-linters.yml/badge.svg?branch=master)](https://github.com/wwakabobik/leonardo_api/actions/workflows/master-linters.yml)\n![PyPI - License](https://img.shields.io/pypi/l/leonardo-api)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/leonardo-api) \n[![Downloads](https://static.pepy.tech/badge/leonardo-api)](https://pepy.tech/project/leonardo-api)\n[![Downloads](https://static.pepy.tech/badge/leonardo-api/month)](https://pepy.tech/project/leonardo-api)\n\nThis package contains Python API for [Leonardo.ai](https://leonardo.ai/) based on official [API documentation](https://docs.leonardo.ai/reference).\n\n![Leonardo.ai interface](https://raw.githubusercontent.com/wwakabobik/leonardo_api/master/src/assets/leonardo_interface.jpg)\n\nTo install the package, please use package from [pypi](https://pypi.org/project/leonardo-api/):\n\n```bash\npip install leonardo-api\n```\n\nThis 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`.\n\nTo start, you must have paid subscription and create an API access token from you [settings page](https://app.leonardo.ai/settings)-\u003eUser API. Then, init manager class with using your access_token:\n\n```python\nfrom leonardo_api import Leonardo\n\nleonardo = Leonardo(auth_token='abcd-1234-5678-90ef-deadbeef00000')\n```\n\nNow you can use all API methods, provided by Leonardo.ai API, i.e. starting getting user info and generating your first image:\n\n```python\nresponse = leonardo.get_user_info()  # get your user info\nresponse = leonardo.post_generations(prompt=\"The quick brown fox jumps over the lazy dog\", num_images=1,\n                                           negative_prompt='schrodinger cat paradox',\n                                           model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768,\n                                           guidance_scale=7)\n```\n\nIn according to API reference, you will get the json answer with content about pending job like following:\n\n```json\n{\"sdGenerationJob\": {\"generationId\": \"123456-0987-aaaa-bbbb-01010101010\"}}\n```\n\nTo obtain your image you need to use additional method:\n\n```python\nresponse = leonardo.get_single_generation(generation_id)  # get it using response['sdGenerationJob']['generationId']\n```\n\nOr, optionally, you may wait for job completion using following method:\n\n```python\nresponse = leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId'])\n```\n\nFinally, you'll get your array of images:\n\n```python\n[{'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': []}]\n```\n\n![The quick brown fox jumps over the lazy dog](https://raw.githubusercontent.com/wwakabobik/leonardo_api/master/src/assets/fox.jpeg)\n\nYou'll find descriptions for rest of the methods in official [API reference](https://docs.leonardo.ai/reference).\n\n---\n\nAs option, you may want to use preloaded dicts with models (nsfw/community/platform):\n\n```python\nfrom leonardo_api import platform_models, custom_models, nsfw_models\n```\n\nWhich contains details of models like following:\n\n```python\n{\n    \"data\": {\n        \"custom_models\": [\n            {\n                \"id\": \"f1929ea3-b169-4c18-a16c-5d58b4292c69\",\n                \"name\": \"RPG v5\",\n                # rest of the model data\n            }\n            # rest models\n        ]\n    }\n}\n```\n\nHave fun and enjoy!\n\n## Donations\nIf you like this project, you can support it by donating via [DonationAlerts](https://www.donationalerts.com/r/rocketsciencegeek).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwwakabobik%2Fleonardo_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwwakabobik%2Fleonardo_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwwakabobik%2Fleonardo_api/lists"}