A library for working with Kandinsky AI image generator API
Project description
KandinskyLib
A library for interacting with the Kandinsky AI image generation API.
Installation
You can install the library using pip:
pip install kandinskylib
Usage
Generator
from kandinskylib import Kandinsky
api_key = 'your_api_key'
secret_key = 'your_secret_key'
client = Kandinsky(api_key, secret_key)
# Generate an image
response = client.generate_image(
prompt="A cat in sunglasses",
scale="3:2",
style="UHD",
negative_prompt="Bright colors, neon colors",
path="./image/generated_image.jpg"
)
print(response)
Available Styles
from kandinskylib import styles
# List available styles
styles_response = styles()
print(styles_response)
Documentation
class Kandinsky
__init__(self, api_key, secret_key)
Initializes the client for API interaction.
-
api_key
(str): Your API key. -
secret_key
(str): Your secret key.get_model(self)
Fetches the model ID for image generation. -
Returns:
str
- The model ID orNone
in case of an error.generate_image(self, prompt, scale='1:1', style='UHD', negative_prompt="Яркие цвета, кислотные цвета", path='./image/generated_image.jpg')
Generates an image based on a text prompt. -
prompt
(str): Text prompt for image generation. The length should be less than 1000 characters. -
scale
(str): Aspect ratio of the image in the format 'w '. Default is '1:1'. -
style
(str): Image style. Default is 'UHD'. -
negative_prompt
(str): Negative text prompt to exclude unwanted elements. -
path
(str): Path to save the generated image. Default is './image/generated_image.jpg'. -
Returns:
str
- Message about the result of the generation._check_generation(self, request_id, attempts=10, delay=10)
Checks the status of image generation.
request_id
(str): Generation request ID.attempts
(int): Number of status check attempts. Default is 10.delay
(int): Delay between status check attempts in seconds. Default is 10.- Returns:
list
- List of generated images in base64 format or raises an exception in case of an error.
_get_max_resolution(self, scale)
Determines the maximum resolution of the image based on the aspect ratio.
scale
(str): Aspect ratio in the format 'w'.- Returns:
tuple
- Width and height of the image.
_save_image(self, base64_str, output_file)
Saves the image to a file.
base64_str
(str): Base64 string of the image.output_file
(str): Path to save the image.
def styles()
Fetches the list of available styles for image generation.
- Returns:
list
- List of available styles.
License
This project is licensed under the terms of the MIT License - see the LICENSE file for details.
Project details
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
File details
Details for the file kandinskylib-0.1.4.tar.gz
.
File metadata
- Download URL: kandinskylib-0.1.4.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2c25c8522399e660c5e5e295b27fbedcdccdeac09ab882c96a2801d3004b47b |
|
MD5 | 34df40ccba71e0d095b9bc6dcc967d21 |
|
BLAKE2b-256 | 68a6754475a74481538ec4c4e56c87f626eb6f2aca8eec672b7e9dd573d5b74b |
File details
Details for the file kandinskylib-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: kandinskylib-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dca842ab3ef1c9d86b9629b9c4856933f465b92d682cda24369f0820ff19435 |
|
MD5 | 01dad572d2dfbaeeb47ecd2ad10397e7 |
|
BLAKE2b-256 | 462d0ded617102c3194bfa5ffcb271111750c438897f072caed3faa46bc9a0fe |