# KandinskyLib
A library for interacting with the Kandinsky AI image generation API.
## Installation
You can install the library using pip:
```bash
pip install kandinskylib
```
# Usage
## Generator
```python
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
```python
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 or `None` 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.
Raw data
{
"_id": null,
"home_page": "https://github.com/Read1dno/kandinskylib",
"name": "kandinskylib",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.6",
"maintainer_email": null,
"keywords": "kandinsky, ai, image generation, api",
"author": "Read1dno",
"author_email": "ef8ser@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/68/a6/754475a74481538ec4c4e56c87f626eb6f2aca8eec672b7e9dd573d5b74b/kandinskylib-0.1.4.tar.gz",
"platform": null,
"description": "# KandinskyLib\r\n\r\nA library for interacting with the Kandinsky AI image generation API.\r\n\r\n## Installation\r\n\r\nYou can install the library using pip:\r\n\r\n```bash\r\npip install kandinskylib\r\n```\r\n\r\n# Usage\r\n\r\n## Generator\r\n\r\n```python\r\nfrom kandinskylib import Kandinsky\r\n\r\napi_key = 'your_api_key'\r\nsecret_key = 'your_secret_key'\r\nclient = Kandinsky(api_key, secret_key)\r\n\r\n# Generate an image\r\nresponse = client.generate_image(\r\n prompt=\"A cat in sunglasses\",\r\n scale=\"3:2\",\r\n style=\"UHD\",\r\n negative_prompt=\"Bright colors, neon colors\",\r\n path=\"./image/generated_image.jpg\"\r\n)\r\nprint(response)\r\n```\r\n\r\n## Available Styles\r\n\r\n```python\r\nfrom kandinskylib import styles\r\n\r\n# List available styles\r\nstyles_response = styles()\r\nprint(styles_response)\r\n```\r\n\r\n# Documentation\r\n`class Kandinsky`\r\n`__init__(self, api_key, secret_key)`\r\nInitializes the client for API interaction.\r\n\r\n- `api_key` (str): Your API key.\r\n- `secret_key` (str): Your secret key.\r\n`get_model(self)`\r\nFetches the model ID for image generation.\r\n\r\n- Returns: `str` - The model ID or `None` in case of an error.\r\n`generate_image(self, prompt, scale='1:1', style='UHD', negative_prompt=\"\u042f\u0440\u043a\u0438\u0435 \u0446\u0432\u0435\u0442\u0430, \u043a\u0438\u0441\u043b\u043e\u0442\u043d\u044b\u0435 \u0446\u0432\u0435\u0442\u0430\", path='./image/generated_image.jpg')`\r\nGenerates an image based on a text prompt.\r\n\r\n- `prompt` (str): Text prompt for image generation. The length should be less than 1000 characters.\r\n- `scale` (str): Aspect ratio of the image in the format 'w\r\n'. Default is '1:1'.\r\n- `style` (str): Image style. Default is 'UHD'.\r\n- `negative_prompt` (str): Negative text prompt to exclude unwanted elements.\r\n- `path` (str): Path to save the generated image. Default is './image/generated_image.jpg'.\r\n- Returns: `str` - Message about the result of the generation.\r\n`_check_generation(self, request_id, attempts=10, delay=10)`\r\n\r\nChecks the status of image generation.\r\n\r\n- `request_id` (str): Generation request ID.\r\n- `attempts` (int): Number of status check attempts. Default is 10.\r\n- `delay` (int): Delay between status check attempts in seconds. Default is 10.\r\n- Returns: `list` - List of generated images in base64 format or raises an exception in case of an error.\r\n\r\n`_get_max_resolution(self, scale)`\r\nDetermines the maximum resolution of the image based on the aspect ratio.\r\n\r\n- `scale` (str): Aspect ratio in the format 'w'.\r\n- Returns: `tuple` - Width and height of the image.\r\n\r\n`_save_image(self, base64_str, output_file)`\r\nSaves the image to a file.\r\n\r\n- `base64_str` (str): Base64 string of the image.\r\n- `output_file` (str): Path to save the image.\r\n \r\n`def styles()`\r\nFetches the list of available styles for image generation.\r\n\r\n- Returns: `list` - List of available styles.\r\n\r\n## License\r\n\r\nThis project is licensed under the terms of the MIT License - see the LICENSE file for details.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A library for working with Kandinsky AI image generator API",
"version": "0.1.4",
"project_urls": {
"Homepage": "https://github.com/Read1dno/kandinskylib"
},
"split_keywords": [
"kandinsky",
" ai",
" image generation",
" api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "462d0ded617102c3194bfa5ffcb271111750c438897f072caed3faa46bc9a0fe",
"md5": "01dad572d2dfbaeeb47ecd2ad10397e7",
"sha256": "7dca842ab3ef1c9d86b9629b9c4856933f465b92d682cda24369f0820ff19435"
},
"downloads": -1,
"filename": "kandinskylib-0.1.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "01dad572d2dfbaeeb47ecd2ad10397e7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.6",
"size": 5311,
"upload_time": "2024-08-03T05:28:49",
"upload_time_iso_8601": "2024-08-03T05:28:49.352107Z",
"url": "https://files.pythonhosted.org/packages/46/2d/0ded617102c3194bfa5ffcb271111750c438897f072caed3faa46bc9a0fe/kandinskylib-0.1.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "68a6754475a74481538ec4c4e56c87f626eb6f2aca8eec672b7e9dd573d5b74b",
"md5": "34df40ccba71e0d095b9bc6dcc967d21",
"sha256": "a2c25c8522399e660c5e5e295b27fbedcdccdeac09ab882c96a2801d3004b47b"
},
"downloads": -1,
"filename": "kandinskylib-0.1.4.tar.gz",
"has_sig": false,
"md5_digest": "34df40ccba71e0d095b9bc6dcc967d21",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.6",
"size": 5147,
"upload_time": "2024-08-03T05:28:51",
"upload_time_iso_8601": "2024-08-03T05:28:51.027356Z",
"url": "https://files.pythonhosted.org/packages/68/a6/754475a74481538ec4c4e56c87f626eb6f2aca8eec672b7e9dd573d5b74b/kandinskylib-0.1.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-03 05:28:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Read1dno",
"github_project": "kandinskylib",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "kandinskylib"
}