Skip to content

Commit 77e2765

Browse files
various modifications
1 parent e02d0d8 commit 77e2765

File tree

10 files changed

+85
-65
lines changed

10 files changed

+85
-65
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__pycache__
22
.pytest_cache
33
.env
4-
core/__pycache__
4+
core/__pycache__
5+
src/pixy/__pycache__

docs/client.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
# Pixy SDK Client API Reference
1+
# PixyClient API Reference
22

3-
The Pixy SDK Client is a Python library that provides a simple interface for interacting with the Pixy SDK. It allows you to generate images, videos, and subtitles using the Pixy API. Using the SDK, offers the following functionalities:
4-
5-
1. Generating images, videos, and subtitles
6-
2. Getting previously generated resources
7-
3. Updating previously generated resources
8-
4. Deleting previously generated resources
9-
10-
## Installation
11-
12-
### <span style="color:red">To be added</span>
3+
The easiest approach to use the Pixy SDK is to initialize a new instance of the PixyClient class, using the API key obtained from the Pixy panel. In this page, we walk through the whole functionalities of the PixyClient class, step by step.
134

145
## Usage
156

16-
### ```PixyClient(api_key: str)```
7+
### 1. ```PixyClient(api_key: str, settings: Settings = Settings)```
178

189
#### Description:
1910
Initializes a new instance of the PixyClient class, given the API key. The API key is verified automatically.
2011

2112
#### Args:
2213
* api_key (str): The API key obtained from the Pixy panel.
14+
* settings (Settings): The settings to use; stick to the default value, unless you have a custom provider. Checkout the [settings documentation]() for a comprehensive instruction on how to declare custom settings.
2315

2416
#### Example:
2517
```python

docs/settings.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# `settings` class
2+
3+
We use a the `settings` class from [settings.py](https://github.com/pixiee-ai/pixy-sdk/blob/main/src/pixy/settings.py) to store the settings that pixy SDK relies on; currently, these settings include:
4+
5+
1. **url_mapping** (dict): The URL mapping to determine the endpoint, given the `generation_type`; stick to the default value, unless you have a custom provider.
6+
2. **properties_mapping** (dict): The properties mapping to determine the type of the `properties`, given the `generation_type`; stick to the default value, unless you have a custom provider.
7+
8+
This class is initialized with the default values; therefore, unless you are using a custom provider, you don't need to worry about the values it contains. Moreover, as this class is a static class, its attributes are accessible without instantiating it.
9+
10+
In case you are using a custom provider, you are supposed to instanciate from this class with custom endpoints, as below:
11+
12+
```python
13+
14+
from pixy.settings import Settings
15+
16+
settings = Settings(
17+
url_mapping = {"image": "https://example.com/image",
18+
"video": "https://example.com/video",
19+
"subtitle": "https://example.com/subtitle"},
20+
)
21+
22+
```
23+
24+
Don't forget to pass the custom settings to the `PixyClient` class, as well. You are supposed to this, once instanciating from the `PixyClient` class:
25+
26+
```python
27+
from pixy.client import PixyClient
28+
29+
# assuming that you have declared the custom settings above
30+
31+
client = PixyClient(api_key, settings)
32+
33+
```
34+
35+
You also need to pass the attributes from the custom `settings` class to the functions from the `pixy.utils` module, as well; checkout the [utils documentation](https://github.com/pixiee-ai/pixy-sdk/blob/main/docs/utils.md) for more details.

docs/utils.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
The Pixy SDK relys on a set of utility function, covering a wide range of tasks. In this section, each of them is discussed individually.
44

5-
## ```verify(api_key: str) -> bool```
5+
## ```verify(api_key: str, url: str = Settings.url_mapping.get("api_key_verification")) -> bool```
66

77
### Description:
88
Verifies the given API key.
99

1010
### Args:
1111
* api_key (str): The API key to verify.
12+
* url (str): The URL to call; stick to the default value, unless you have a custom provider.
1213

1314
### Returns:
1415
* bool: True if the API key is valid, False otherwise.
1516

1617
### Example:
1718
```python
18-
from core.utils import verify
19+
from pixy.utils import verify
1920

2021
api_key = "your_api_key"
2122
is_valid = verify(api_key)
@@ -24,7 +25,7 @@ print(is_valid)
2425
>>> True
2526
```
2627

27-
## ```generate(generation_type: str, properties: ImageGenProperties | VideoGenProperties | SubtitleGenProperties api_key: str,) -> dict```
28+
## ```generate(generation_type: str, properties: ImageGenProperties | VideoGenProperties | SubtitleGenProperties api_key: str, url_mapping: dict = Settings.url_mapping, properties_mapping: dict = Settings.properties_mapping,) -> dict```
2829

2930
### Description:
3031
Generates a resource (image, video, subtitle) based on the given properties.
@@ -33,14 +34,16 @@ Generates a resource (image, video, subtitle) based on the given properties.
3334
* generation_type (str): The type of resource to generate; current valid choices are "image", "video" and "subtitle".
3435
* properties (ImageGenProperties | VideoGenProperties | SubtitleGenProperties): The properties of the resource to generate; current valid choices are ImageGenProperties, VideoGenProperties and SubtitleGenProperties that correspond to "image", "video" and "subtitle", respectively.
3536
* api_key (str): The API key to use for the request.
37+
* url_mapping (dict): The URL mapping to determine the endpoint, given the `generation_type`; stick to the default value, unless you have a custom provider.
38+
* properties_mapping (dict): The properties mapping to determine the type of the `properties`, given the `generation_type`; stick to the default value, unless you have a custom provider.
3639

3740
### Returns:
3841
* dict: A JSON response containing the generated resource.
3942

4043
### Example:
4144
```python
42-
from core.utils import generate
43-
from core.schemas import ImageGenProperties
45+
from pixy.utils import generate
46+
from pixy.schemas import ImageGenProperties
4447

4548
api_key = "your_api_key"
4649
generation_type = "image"
@@ -94,7 +97,7 @@ print(resource)
9497
>>>}
9598
```
9699

97-
## ```get_by_uid(generation_type: str, uid: str, api_key: str) -> dict```
100+
## ```get_by_uid(generation_type: str, uid: str, api_key: str, url_mapping: dict = Settings.url_mapping) -> dict```
98101

99102
### Description:
100103
Retrieves a resource by its unique identifier (UID).
@@ -103,14 +106,15 @@ Retrieves a resource by its unique identifier (UID).
103106
* generation_type (str): The type of resource to retrieve; current valid choices are "image", "video" and "subtitle".
104107
* uid (str): The desired UID.
105108
* api_key (str): The API key to use for the request.
109+
* url_mapping (dict): The URL mapping to determine the endpoint, given the `generation_type`; stick to the default value, unless you have a custom provider.
106110

107111
### Returns:
108112
* dict: A JSON response inclding the desired resource.
109113

110114
### Example:
111115

112116
```python
113-
from core.utils import get_by_uid
117+
from pixy.utils import get_by_uid
114118

115119
api_key = "your_api_key"
116120
generation_type = "image"
@@ -160,24 +164,26 @@ print(resource)
160164
>>>}
161165
```
162166

163-
## ```get_list(generation_type: str, params: GetListParameters | None, api_key: str) -> dict```
167+
## ```get_list(generation_type: str, api_key: str, params: GetListParameters | None = None, url_mapping: dict = Settings.url_mapping,
168+
) -> dict```
164169

165170
### Description:
166171
Retrieves a list of resources filtered by the given parameters.
167172

168173
### Args:
169174
* generation_type (str): The type of resource to retrieve.
170-
* params (GetListParameters | None): The parameters to filter the results by.
171175
* api_key (str): The API key to use for the request.
176+
* params (GetListParameters | None): The parameters to filter the results by; the default value is `None`.
177+
* url_mapping (dict): The URL mapping to determine the endpoint, given the `generation_type`; stick to the default value, unless you have a custom provider.
172178

173179
### Returns:
174180
* dict: A JSON response containing the retrieved resources.
175181

176182
### Example:
177183

178184
```python
179-
from core.schemas import GetListParameters
180-
from core.utils import get_list
185+
from pixy.schemas import GetListParameters
186+
from pixy.utils import get_list
181187

182188
api_key = "your_api_key"
183189
generation_type = "image"
@@ -191,10 +197,10 @@ params = GetListParameters(
191197

192198
resources = get_list(
193199
generation_type,
194-
params,
195200
api_key
201+
params,
196202
)
197-
print(lenresources)
203+
print(resources)
198204

199205
{
200206
"items": [
@@ -279,7 +285,7 @@ print(lenresources)
279285
}
280286
```
281287

282-
## ```delete(generation_type: str, uid: str, api_key: str) -> dict```
288+
## ```delete(generation_type: str, uid: str, api_key: str, url_mapping: dict = Settings.url_mapping) -> dict```
283289

284290
### Description:
285291
Deletes a resource by its unique identifier.
@@ -288,14 +294,15 @@ Deletes a resource by its unique identifier.
288294
* generation_type (str): The type of resource to delete.
289295
* uid (str): The unique identifier of the resource.
290296
* api_key (str): The API key to use for the request.
297+
* url_mapping (dict): The URL mapping to determine the endpoint, given the `generation_type`; stick to the default value, unless you have a custom provider.
291298

292299
### Returns:
293300
* dict: A JSON response indicating the result of the deletion.
294301

295302
### Example:
296303

297304
```python
298-
from core.utils import delete
305+
from pixy.utils import delete
299306

300307
api_key = "your_api_key"
301308
generation_type = "image"
@@ -343,7 +350,7 @@ response = delete(generation_type, uid, api_key)
343350
}
344351
```
345352

346-
## ```update(generation_type: str, uid: str, properties: dict, api_key: str) -> dict```
353+
## ```update(generation_type: str, uid: str, properties: dict, api_key: str, url_mapping: dict = Settings.url_mapping) -> dict```
347354

348355
### Description:
349356
Updates a resource by its unique identifier with the given properties.
@@ -353,13 +360,14 @@ Updates a resource by its unique identifier with the given properties.
353360
* uid (str): The unique identifier of the resource.
354361
* properties (dict): The properties to update the resource with. This is supposed to only include the key-values to update.
355362
* api_key (str): The API key to use for the request.
363+
* url_mapping (dict): The URL mapping to determine the endpoint, given the `generation_type`; stick to the default value, unless you have a custom provider.
356364

357365
### Returns:
358366
* dict: A JSON response containing the updated resource.
359367

360368
### Example:
361369
```python
362-
from core.utils import update
370+
from pixy.utils import update
363371

364372
api_key = "your_api_key"
365373
generation_type = "image"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pixy-sdk"
7-
version = "0.0.8"
7+
version = "0.0.9"
88
description = "A python sdk for pixy."
99
readme = "README.md"
1010
requires-python = ">=3.9"

src/pixy/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
class PixyClient:
19-
def __init__(self, api_key: str, settings: Settings = Settings()):
19+
def __init__(self, api_key: str, settings: Settings = Settings):
2020
"""
2121
Initialize the Pixy client.
2222

src/pixy/settings.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
11
from .schemas import ImageGenProperties, VideoGenProperties, SubtitleGenProperties
22

33

4-
class _Settings:
5-
4+
class Settings:
65
url_mapping = {
76
"api_key_verification": "https://sso.pixy.ir/api_key/verify",
87
"image": "https://media.pixy.ir/v1/apps/imagine/imagination/",
98
"video": "https://media.pixy.ir/v1/apps/videogen/videos/",
109
"subtitle": "https://media.pixy.ir/v1/apps/subtitle/subtitles/",
1110
}
12-
1311
properties_mapping = {
1412
"image": ImageGenProperties,
1513
"video": VideoGenProperties,
1614
"subtitle": SubtitleGenProperties,
1715
}
1816

19-
20-
class Settings:
21-
def __init__(
22-
self,
23-
url_mapping: dict = {
24-
"api_key_verification": "https://sso.pixy.ir/api_key/verify",
25-
"image": "https://media.pixy.ir/v1/apps/imagine/imagination/",
26-
"video": "https://media.pixy.ir/v1/apps/videogen/videos/",
27-
"subtitle": "https://media.pixy.ir/v1/apps/subtitle/subtitles/",
28-
},
29-
properties_mapping: dict = {
30-
"image": ImageGenProperties,
31-
"video": VideoGenProperties,
32-
"subtitle": SubtitleGenProperties,
33-
},
34-
):
35-
self.url_mapping = url_mapping
36-
self.properties_mapping = properties_mapping
17+
def __init__(self, url_mapping: dict = None, properties_mapping: dict = None):
18+
if url_mapping is not None:
19+
self.url_mapping = url_mapping
20+
if properties_mapping is not None:
21+
self.properties_mapping = properties_mapping

src/pixy/utils.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
logger.addHandler(console_handler)
1515

1616
logger.setLevel(logging.INFO)
17-
settings = Settings()
1817

1918

2019
def verify(
21-
api_key: str, url: str = settings.url_mapping.get("api_key_verification")
20+
api_key: str, url: str = Settings.url_mapping.get("api_key_verification")
2221
) -> bool:
2322
"""
2423
Verifies the given API key.
@@ -58,8 +57,8 @@ def generate(
5857
generation_type: str,
5958
properties: ImageGenProperties | VideoGenProperties | SubtitleGenProperties,
6059
api_key: str,
61-
url_mapping: dict = settings.url_mapping,
62-
properties_mapping: dict = settings.properties_mapping,
60+
url_mapping: dict = Settings.url_mapping,
61+
properties_mapping: dict = Settings.properties_mapping,
6362
) -> dict:
6463
"""
6564
Generates a resource (image, video, subtitle) based on the given properties.
@@ -130,7 +129,7 @@ def get_by_uid(
130129
generation_type: str,
131130
uid: str,
132131
api_key: str,
133-
url_mapping: dict = settings.url_mapping,
132+
url_mapping: dict = Settings.url_mapping,
134133
) -> dict:
135134
"""
136135
Retrieves a resource by its unique identifier (UID).
@@ -166,8 +165,8 @@ def get_list(
166165
generation_type: str,
167166
api_key: str,
168167
params: GetListParameters | None = None,
169-
url_mapping: dict = settings.url_mapping,
170-
):
168+
url_mapping: dict = Settings.url_mapping,
169+
) -> dict:
171170
"""
172171
Retrieves a list of resources filtered by the given parameters.
173172
@@ -205,7 +204,7 @@ def delete(
205204
generation_type: str,
206205
uid: str,
207206
api_key: str,
208-
url_mapping: dict = settings.url_mapping,
207+
url_mapping: dict = Settings.url_mapping,
209208
) -> dict:
210209
"""
211210
Deletes a resource by its unique identifier.
@@ -243,7 +242,7 @@ def update(
243242
uid: str,
244243
properties: dict,
245244
api_key: str,
246-
url_mapping: dict = settings.url_mapping,
245+
url_mapping: dict = Settings.url_mapping,
247246
) -> dict:
248247
"""
249248
Updates a resource by its unique identifier with the given properties.

tests/test_schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pixy.schemas import (
1+
from src.pixy.schemas import (
22
ImageGenEngine,
33
ImageGenProperties,
44
SubtitleGenProperties,

tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from pixy.utils import verify, generate
2-
from core.schemas import ImageGenProperties, SubtitleGenProperties
1+
from src.pixy.utils import verify, generate
2+
from src.pixy.schemas import ImageGenProperties, SubtitleGenProperties
33
import pytest
44
from pydantic import BaseModel
55
from typing import Literal

0 commit comments

Comments
 (0)