syrtis-python-client 0.0.6__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {syrtis_python_client-0.0.6 → syrtis_python_client-0.0.8}/PKG-INFO +2 -3
- {syrtis_python_client-0.0.6 → syrtis_python_client-0.0.8}/README.md +1 -1
- {syrtis_python_client-0.0.6 → syrtis_python_client-0.0.8}/pyproject.toml +2 -4
- syrtis_python_client-0.0.8/src/syrtis_python_client/__init__.py +7 -0
- {syrtis_python_client-0.0.6/src/syrtis_python_client → syrtis_python_client-0.0.8/src/syrtis_python_client/common}/__init__.py +0 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/common/entity_schemas.py +11 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/common/generated_entity_schemas.py +25 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/common/generated_repositories.py +18 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/common/syrtis_client.py +100 -0
- syrtis_python_client-0.0.6/src/syrtis_python_client/py.typed → syrtis_python_client-0.0.8/src/syrtis_python_client/data/__init__.py +0 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/data/entity/__init__.py +0 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/data/entity/message.json +672 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/data/entity/message_stamp.json +140 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/data/entity/request.json +495 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/data/entity/session.json +364 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/data/entity/user.json +268 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/entity/__init__.py +0 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/entity/abstract_api_entity.py +25 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/entity/message.py +14 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/entity/message_stamp.py +9 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/entity/request.py +9 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/entity/session.py +9 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/entity/user.py +9 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/py.typed +0 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/repository/__init__.py +0 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/repository/abstract_api_repository.py +37 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/repository/message_repository.py +12 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/repository/message_stamp_repository.py +12 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/repository/request_repository.py +12 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/repository/session_repository.py +50 -0
- syrtis_python_client-0.0.8/src/syrtis_python_client/repository/user_repository.py +12 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: syrtis-python-client
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Author-Email: weeger <contact@syrtis.ai>
|
|
5
5
|
License: MIT
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
7
7
|
Classifier: License :: OSI Approved :: MIT License
|
|
8
8
|
Classifier: Operating System :: OS Independent
|
|
9
9
|
Requires-Python: >=3.10
|
|
10
|
-
Requires-Dist: pydantic<3,>=2
|
|
11
10
|
Provides-Extra: dev
|
|
12
11
|
Requires-Dist: pytest; extra == "dev"
|
|
13
12
|
Requires-Dist: pytest-cov; extra == "dev"
|
|
@@ -15,7 +14,7 @@ Description-Content-Type: text/markdown
|
|
|
15
14
|
|
|
16
15
|
# syrtis-python-client
|
|
17
16
|
|
|
18
|
-
Version: 0.0.
|
|
17
|
+
Version: 0.0.8
|
|
19
18
|
|
|
20
19
|
## Table of Contents
|
|
21
20
|
|
|
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "syrtis-python-client"
|
|
9
|
-
version = "0.0.
|
|
9
|
+
version = "0.0.8"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name = "weeger", email = "contact@syrtis.ai" },
|
|
12
12
|
]
|
|
@@ -16,9 +16,7 @@ classifiers = [
|
|
|
16
16
|
"License :: OSI Approved :: MIT License",
|
|
17
17
|
"Operating System :: OS Independent",
|
|
18
18
|
]
|
|
19
|
-
dependencies = [
|
|
20
|
-
"pydantic>=2,<3",
|
|
21
|
-
]
|
|
19
|
+
dependencies = []
|
|
22
20
|
|
|
23
21
|
[project.readme]
|
|
24
22
|
file = "README.md"
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from syrtis_python_client.common.generated_entity_schemas import (
|
|
6
|
+
get_generated_entity_schemas,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_entity_schemas() -> dict[str, dict[str, Any]]:
|
|
11
|
+
return get_generated_entity_schemas()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from importlib.resources import files
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
ENTITY_SCHEMA_FILES = [
|
|
8
|
+
"message.json",
|
|
9
|
+
"message_stamp.json",
|
|
10
|
+
"request.json",
|
|
11
|
+
"session.json",
|
|
12
|
+
"user.json",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_generated_entity_schemas() -> dict[str, dict[str, Any]]:
|
|
17
|
+
data_package = "syrtis_python_client.data.entity"
|
|
18
|
+
schemas: dict[str, dict[str, Any]] = {}
|
|
19
|
+
|
|
20
|
+
for file_name in ENTITY_SCHEMA_FILES:
|
|
21
|
+
schema_file = files(data_package).joinpath(file_name)
|
|
22
|
+
schema = json.loads(schema_file.read_text(encoding="utf-8"))
|
|
23
|
+
schemas[schema["name"]] = schema
|
|
24
|
+
|
|
25
|
+
return schemas
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from syrtis_python_client.repository.message_repository import MessageRepository
|
|
4
|
+
from syrtis_python_client.repository.message_stamp_repository import (
|
|
5
|
+
MessageStampRepository,
|
|
6
|
+
)
|
|
7
|
+
from syrtis_python_client.repository.request_repository import RequestRepository
|
|
8
|
+
from syrtis_python_client.repository.session_repository import SessionRepository
|
|
9
|
+
from syrtis_python_client.repository.user_repository import UserRepository
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
generated_repositories = [
|
|
13
|
+
MessageRepository,
|
|
14
|
+
MessageStampRepository,
|
|
15
|
+
RequestRepository,
|
|
16
|
+
SessionRepository,
|
|
17
|
+
UserRepository,
|
|
18
|
+
]
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
from urllib import parse, request
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
from syrtis_python_client.common.entity_schemas import get_entity_schemas
|
|
8
|
+
from syrtis_python_client.common.generated_repositories import generated_repositories
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SyrtisClient:
|
|
12
|
+
DEFAULT_BASE_URL = "https://api.syrtis.ai/api/"
|
|
13
|
+
|
|
14
|
+
def __init__(self, base_url: str | None = None, api_key: str | None = None) -> None:
|
|
15
|
+
self.base_url = (base_url or self.DEFAULT_BASE_URL).rstrip("/") + "/"
|
|
16
|
+
self.api_key = api_key
|
|
17
|
+
self._repositories: dict[type[Any], Any] = {}
|
|
18
|
+
|
|
19
|
+
def get_repository_classes(self) -> list[type[Any]]:
|
|
20
|
+
return list(generated_repositories)
|
|
21
|
+
|
|
22
|
+
def get_entity_schemas(self) -> dict[str, dict[str, Any]]:
|
|
23
|
+
return get_entity_schemas()
|
|
24
|
+
|
|
25
|
+
def get_repository(self, entity_type: type[Any]) -> Any:
|
|
26
|
+
if entity_type in self._repositories:
|
|
27
|
+
return self._repositories[entity_type]
|
|
28
|
+
|
|
29
|
+
for repository_class in self.get_repository_classes():
|
|
30
|
+
if repository_class.get_entity_type() is entity_type:
|
|
31
|
+
repository = repository_class(self)
|
|
32
|
+
self._repositories[entity_type] = repository
|
|
33
|
+
return repository
|
|
34
|
+
|
|
35
|
+
raise LookupError(
|
|
36
|
+
f"No repository found for entity type: {entity_type.__name__}"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def request_json(
|
|
40
|
+
self,
|
|
41
|
+
method: str,
|
|
42
|
+
path: str,
|
|
43
|
+
*,
|
|
44
|
+
params: dict[str, Any] | None = None,
|
|
45
|
+
payload: dict[str, Any] | None = None,
|
|
46
|
+
) -> Any:
|
|
47
|
+
url = self.base_url + path.lstrip("/")
|
|
48
|
+
if params:
|
|
49
|
+
url = f"{url}?{parse.urlencode(params, doseq=True)}"
|
|
50
|
+
|
|
51
|
+
headers = {"Accept": "application/json"}
|
|
52
|
+
body: bytes | None = None
|
|
53
|
+
|
|
54
|
+
if self.api_key:
|
|
55
|
+
headers["Authorization"] = f"Bearer {self.api_key}"
|
|
56
|
+
|
|
57
|
+
if payload is not None:
|
|
58
|
+
body = json.dumps(payload).encode("utf-8")
|
|
59
|
+
headers["Content-Type"] = "application/json"
|
|
60
|
+
|
|
61
|
+
req = request.Request(
|
|
62
|
+
url=url, method=method.upper(), data=body, headers=headers
|
|
63
|
+
)
|
|
64
|
+
with request.urlopen(req) as response:
|
|
65
|
+
raw = response.read().decode("utf-8")
|
|
66
|
+
if not raw:
|
|
67
|
+
return None
|
|
68
|
+
return json.loads(raw)
|
|
69
|
+
|
|
70
|
+
def request_multipart(
|
|
71
|
+
self,
|
|
72
|
+
method: str,
|
|
73
|
+
path: str,
|
|
74
|
+
*,
|
|
75
|
+
data: dict[str, Any],
|
|
76
|
+
) -> Any:
|
|
77
|
+
url = self.base_url + path.lstrip("/")
|
|
78
|
+
boundary = "----PythonClientBoundary"
|
|
79
|
+
body = (
|
|
80
|
+
f"--{boundary}\r\n"
|
|
81
|
+
f'Content-Disposition: form-data; name="data"\r\n\r\n'
|
|
82
|
+
f"{json.dumps(data)}\r\n"
|
|
83
|
+
f"--{boundary}--\r\n"
|
|
84
|
+
).encode()
|
|
85
|
+
|
|
86
|
+
headers = {
|
|
87
|
+
"Accept": "application/json",
|
|
88
|
+
"Content-Type": f"multipart/form-data; boundary={boundary}",
|
|
89
|
+
}
|
|
90
|
+
if self.api_key:
|
|
91
|
+
headers["Authorization"] = f"Bearer {self.api_key}"
|
|
92
|
+
|
|
93
|
+
req = request.Request(
|
|
94
|
+
url=url, method=method.upper(), data=body, headers=headers
|
|
95
|
+
)
|
|
96
|
+
with request.urlopen(req) as response:
|
|
97
|
+
raw = response.read().decode("utf-8")
|
|
98
|
+
if not raw:
|
|
99
|
+
return None
|
|
100
|
+
return json.loads(raw)
|
|
File without changes
|
|
File without changes
|