SCPYTSDK 0.1.0__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.
- scpytsdk-0.1.0/PKG-INFO +13 -0
- scpytsdk-0.1.0/README.md +2 -0
- scpytsdk-0.1.0/pyproject.toml +18 -0
- scpytsdk-0.1.0/pyproject.toml.orig +17 -0
- scpytsdk-0.1.0/src/scpytsdk/__init__.py +92 -0
- scpytsdk-0.1.0/src/scpytsdk/classes.py +47 -0
- scpytsdk-0.1.0/src/scpytsdk/enums.py +16 -0
- scpytsdk-0.1.0/src/scpytsdk/exceptions.py +8 -0
- scpytsdk-0.1.0/src/scpytsdk/py.typed +0 -0
scpytsdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: SCPYTSDK
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Super Cool Python SDK for Turso Platform API
|
|
5
|
+
Author: FrancyAngy
|
|
6
|
+
Author-email: FrancyAngy <francesco@scsdc-co.org>
|
|
7
|
+
Requires-Dist: pyjwt>=2.13.0
|
|
8
|
+
Requires-Dist: requests>=2.34.2
|
|
9
|
+
Requires-Python: >=3.14
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# PYTSDK
|
|
13
|
+
This is an sdk for the [Turso Platform API](https://docs.turso.tech/api-reference/introduction) which I decided to make since there previously was none.
|
scpytsdk-0.1.0/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "SCPYTSDK"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Super Cool Python SDK for Turso Platform API"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.14"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"pyjwt>=2.13.0",
|
|
9
|
+
"requests>=2.34.2",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[[project.authors]]
|
|
13
|
+
name = "FrancyAngy"
|
|
14
|
+
email = "francesco@scsdc-co.org"
|
|
15
|
+
|
|
16
|
+
[build-system]
|
|
17
|
+
requires = ["uv_build>=0.12.5,<0.13.0"]
|
|
18
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "SCPYTSDK"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Super Cool Python SDK for Turso Platform API"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "FrancyAngy", email = "francesco@scsdc-co.org" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.14"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"pyjwt>=2.13.0",
|
|
12
|
+
"requests>=2.34.2",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
requires = ["uv_build>=0.12.5,<0.13.0"]
|
|
17
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from scpytsdk.classes import Database
|
|
3
|
+
from scpytsdk.exceptions import InvalidApikey, InvalidOrganization, DatabaseNotFound
|
|
4
|
+
|
|
5
|
+
class SCPYTSDK:
|
|
6
|
+
_endpoint: str = "https://api.turso.tech"
|
|
7
|
+
_apikey: str = ""
|
|
8
|
+
_organization: str = ""
|
|
9
|
+
_headers: dict = {}
|
|
10
|
+
|
|
11
|
+
def __init__(self, apikey: str, organization_slug: str, endpoint: str = "https://api.turso.tech"):
|
|
12
|
+
if apikey == "":
|
|
13
|
+
raise InvalidApikey
|
|
14
|
+
|
|
15
|
+
if organization_slug == "":
|
|
16
|
+
raise InvalidOrganization
|
|
17
|
+
|
|
18
|
+
self._endpoint = endpoint
|
|
19
|
+
|
|
20
|
+
r = requests.get(f"{endpoint}/v1/auth/validate", headers={"Authorization": f"Bearer {apikey}"})
|
|
21
|
+
|
|
22
|
+
if r.status_code != 200:
|
|
23
|
+
print(r.status_code)
|
|
24
|
+
print(dict(r.json()))
|
|
25
|
+
raise InvalidApikey
|
|
26
|
+
|
|
27
|
+
self._apikey = apikey
|
|
28
|
+
|
|
29
|
+
if requests.get(f"{endpoint}/v1/organizations/{organization_slug}", headers={"Authorization": f"Bearer {apikey}"}).status_code != 200:
|
|
30
|
+
raise InvalidOrganization
|
|
31
|
+
|
|
32
|
+
self._organization = organization_slug
|
|
33
|
+
|
|
34
|
+
self._headers = {"Authorization": f"Bearer {apikey}"}
|
|
35
|
+
|
|
36
|
+
def list_dbs(self, group_filter: str | None = None, schema_filter: str | None = None, parent_filter: str | Database | None = None) -> list[Database]:
|
|
37
|
+
filters = ""
|
|
38
|
+
|
|
39
|
+
if group_filter:
|
|
40
|
+
filters += f"?group={group_filter}"
|
|
41
|
+
|
|
42
|
+
if schema_filter:
|
|
43
|
+
if filters == "":
|
|
44
|
+
filters += "?"
|
|
45
|
+
else:
|
|
46
|
+
filters += "&"
|
|
47
|
+
|
|
48
|
+
filters += f"schema={schema_filter}"
|
|
49
|
+
|
|
50
|
+
if parent_filter:
|
|
51
|
+
if filters == "":
|
|
52
|
+
filters += "?"
|
|
53
|
+
else:
|
|
54
|
+
filters += "&"
|
|
55
|
+
|
|
56
|
+
if isinstance(parent_filter, Database):
|
|
57
|
+
filters += f"parent={parent_filter.DbId}"
|
|
58
|
+
else:
|
|
59
|
+
filters += f"parent={parent_filter}"
|
|
60
|
+
|
|
61
|
+
r = requests.get(f"{self._endpoint}/v1/organizations/{self._organization}/databases{filters}", headers=self._headers)
|
|
62
|
+
|
|
63
|
+
json = r.json()
|
|
64
|
+
|
|
65
|
+
dbs: list[Database] = []
|
|
66
|
+
|
|
67
|
+
for db_json in json["databases"]:
|
|
68
|
+
dbs += [Database(**db_json)]
|
|
69
|
+
|
|
70
|
+
return dbs
|
|
71
|
+
|
|
72
|
+
def delete_db(self, database: str | Database) -> None:
|
|
73
|
+
r = requests.Response()
|
|
74
|
+
|
|
75
|
+
if isinstance(database, Database):
|
|
76
|
+
r = requests.delete(f"https://api.turso.tech/v1/organizations/{self._organization}/databases/{database.Name}", headers=self._headers)
|
|
77
|
+
else:
|
|
78
|
+
r = requests.delete(f"https://api.turso.tech/v1/organizations/{self._organization}/databases/{database}", headers=self._headers)
|
|
79
|
+
|
|
80
|
+
if r.status_code == 404:
|
|
81
|
+
raise DatabaseNotFound()
|
|
82
|
+
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
def retreive_db(self, database: str | Database) -> Database:
|
|
86
|
+
r = requests.Response()
|
|
87
|
+
if isinstance(database, Database):
|
|
88
|
+
r = requests.get(f"{self._endpoint}/v1/organizations/{self._organization}/databases/{database.Name}")
|
|
89
|
+
else:
|
|
90
|
+
r = requests.get(f"{self._endpoint}/v1/organizations/{self._organization}/databases/{database.Name}")
|
|
91
|
+
|
|
92
|
+
return Database(r.json()["database"])
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from uuid import UUID
|
|
2
|
+
from dataclasses import dataclass, fields
|
|
3
|
+
from scpytsdk.enums import Region
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import get_args, get_origin, get_type_hints
|
|
6
|
+
|
|
7
|
+
def _convert_value(value, target_type):
|
|
8
|
+
if isinstance(target_type, type) and issubclass(target_type, Enum):
|
|
9
|
+
if not isinstance(value, target_type):
|
|
10
|
+
return target_type(value)
|
|
11
|
+
return value
|
|
12
|
+
|
|
13
|
+
origin = get_origin(target_type)
|
|
14
|
+
args = get_args(target_type)
|
|
15
|
+
|
|
16
|
+
if origin is list and args:
|
|
17
|
+
item_type = args[0]
|
|
18
|
+
return [_convert_value(item, item_type) for item in value]
|
|
19
|
+
|
|
20
|
+
return value
|
|
21
|
+
|
|
22
|
+
@dataclass(init=False)
|
|
23
|
+
class Database:
|
|
24
|
+
Name: str
|
|
25
|
+
DbId: UUID
|
|
26
|
+
Hostname: str
|
|
27
|
+
block_reads: bool
|
|
28
|
+
block_writes: bool
|
|
29
|
+
delete_protection: bool
|
|
30
|
+
regions: list[Region]
|
|
31
|
+
primaryRegion: Region
|
|
32
|
+
group: str
|
|
33
|
+
|
|
34
|
+
def __init__(self, **kwargs):
|
|
35
|
+
type_hints = get_type_hints(type(self))
|
|
36
|
+
|
|
37
|
+
for field in fields(self):
|
|
38
|
+
if field.name not in kwargs:
|
|
39
|
+
continue
|
|
40
|
+
|
|
41
|
+
value = kwargs[field.name]
|
|
42
|
+
field_type = type_hints.get(field.name, field.type)
|
|
43
|
+
|
|
44
|
+
value = _convert_value(value, field_type)
|
|
45
|
+
|
|
46
|
+
setattr(self, field.name, value)
|
|
47
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
class Region(str, Enum):
|
|
4
|
+
AWS_TOKYO = "aws-ap-northeast-1"
|
|
5
|
+
AWS_MUMBAI = "aws-ap-south-1"
|
|
6
|
+
AWS_IRELAND = "aws-eu-west-1"
|
|
7
|
+
AWS_VIRGINIA = "aws-us-east-1"
|
|
8
|
+
AWS_OHIO = "aws-us-east-2"
|
|
9
|
+
AWS_OREGON = "aws-us-west-1"
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
def _missing_(cls, value):
|
|
13
|
+
unknown = str.__new__(cls, value)
|
|
14
|
+
unknown._name_ = "UNKNOWN"
|
|
15
|
+
unknown._value_ = value
|
|
16
|
+
return unknown
|
|
File without changes
|