python-open-router 0.1.0__tar.gz → 0.2.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.
- {python_open_router-0.1.0 → python_open_router-0.2.0}/PKG-INFO +1 -1
- {python_open_router-0.1.0 → python_open_router-0.2.0}/pyproject.toml +6 -6
- {python_open_router-0.1.0 → python_open_router-0.2.0}/src/python_open_router/__init__.py +14 -0
- python_open_router-0.2.0/src/python_open_router/models.py +58 -0
- {python_open_router-0.1.0 → python_open_router-0.2.0}/src/python_open_router/open_router.py +22 -2
- python_open_router-0.1.0/src/python_open_router/models.py +0 -25
- {python_open_router-0.1.0 → python_open_router-0.2.0}/LICENSE.md +0 -0
- {python_open_router-0.1.0 → python_open_router-0.2.0}/README.md +0 -0
- {python_open_router-0.1.0 → python_open_router-0.2.0}/src/python_open_router/exceptions.py +0 -0
- {python_open_router-0.1.0 → python_open_router-0.2.0}/src/python_open_router/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "python_open_router"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "Asynchronous Python client for Open Router."
|
|
5
5
|
authors = ["Joost Lekkerkerker <joostlek@outlook.com>"]
|
|
6
6
|
maintainers = ["Joost Lekkerkerker <joostlek@outlook.com>"]
|
|
@@ -39,14 +39,14 @@ coverage = {version = "7.6.12", extras = ["toml"]}
|
|
|
39
39
|
mypy = "1.15.0"
|
|
40
40
|
pre-commit = "4.1.0"
|
|
41
41
|
pre-commit-hooks = "5.0.0"
|
|
42
|
-
pylint = "3.3.
|
|
43
|
-
pytest = "8.3.
|
|
42
|
+
pylint = "3.3.6"
|
|
43
|
+
pytest = "8.3.5"
|
|
44
44
|
pytest-asyncio = "0.25.3"
|
|
45
|
-
pytest-cov = "6.
|
|
45
|
+
pytest-cov = "6.1.1"
|
|
46
46
|
ruff = "0.9.6"
|
|
47
|
-
safety = "3.3.
|
|
47
|
+
safety = "3.3.1"
|
|
48
48
|
yamllint = "1.35.1"
|
|
49
|
-
syrupy = "4.
|
|
49
|
+
syrupy = "4.9.1"
|
|
50
50
|
aioresponses = "0.7.8"
|
|
51
51
|
|
|
52
52
|
[tool.poetry.urls]
|
|
@@ -5,9 +5,23 @@ from python_open_router.exceptions import (
|
|
|
5
5
|
OpenRouterConnectionError,
|
|
6
6
|
OpenRouterError,
|
|
7
7
|
)
|
|
8
|
+
from python_open_router.models import (
|
|
9
|
+
CreatedKey,
|
|
10
|
+
CreateKeyDataWrapper,
|
|
11
|
+
Key,
|
|
12
|
+
KeyData,
|
|
13
|
+
KeyDataWrapper,
|
|
14
|
+
KeysDataWrapper,
|
|
15
|
+
)
|
|
8
16
|
from python_open_router.open_router import OpenRouterClient
|
|
9
17
|
|
|
10
18
|
__all__ = [
|
|
19
|
+
"CreateKeyDataWrapper",
|
|
20
|
+
"CreatedKey",
|
|
21
|
+
"Key",
|
|
22
|
+
"KeyData",
|
|
23
|
+
"KeyDataWrapper",
|
|
24
|
+
"KeysDataWrapper",
|
|
11
25
|
"OpenRouterAuthenticationError",
|
|
12
26
|
"OpenRouterClient",
|
|
13
27
|
"OpenRouterConnectionError",
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Models for OpenRouter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from mashumaro.mixins.orjson import DataClassORJSONMixin
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class KeyDataWrapper(DataClassORJSONMixin):
|
|
12
|
+
"""Wrapper for OpenRouter key data."""
|
|
13
|
+
|
|
14
|
+
data: KeyData
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class KeyData(DataClassORJSONMixin):
|
|
19
|
+
"""The OpenRouter key data."""
|
|
20
|
+
|
|
21
|
+
label: str
|
|
22
|
+
usage: int
|
|
23
|
+
is_provisioning_key: bool
|
|
24
|
+
limit_remaining: int | None
|
|
25
|
+
is_free_tier: bool
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class KeysDataWrapper(DataClassORJSONMixin):
|
|
30
|
+
"""Wrapper for OpenRouter key data."""
|
|
31
|
+
|
|
32
|
+
data: list[Key]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class CreateKeyDataWrapper(DataClassORJSONMixin):
|
|
37
|
+
"""Wrapper for OpenRouter key data."""
|
|
38
|
+
|
|
39
|
+
data: CreatedKey
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class Key(DataClassORJSONMixin):
|
|
44
|
+
"""The OpenRouter key data."""
|
|
45
|
+
|
|
46
|
+
hash: str
|
|
47
|
+
name: str
|
|
48
|
+
label: str
|
|
49
|
+
disabled: bool
|
|
50
|
+
limit: float
|
|
51
|
+
usage: float = 0.0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(kw_only=True)
|
|
55
|
+
class CreatedKey(Key):
|
|
56
|
+
"""Created key."""
|
|
57
|
+
|
|
58
|
+
key: str
|
|
@@ -9,11 +9,17 @@ import socket
|
|
|
9
9
|
from typing import TYPE_CHECKING, Any
|
|
10
10
|
|
|
11
11
|
from aiohttp import ClientError, ClientResponseError, ClientSession
|
|
12
|
-
from aiohttp.hdrs import METH_GET
|
|
12
|
+
from aiohttp.hdrs import METH_GET, METH_POST
|
|
13
13
|
from yarl import URL
|
|
14
14
|
|
|
15
15
|
from python_open_router.exceptions import OpenRouterConnectionError
|
|
16
|
-
from python_open_router.models import
|
|
16
|
+
from python_open_router.models import (
|
|
17
|
+
CreateKeyDataWrapper,
|
|
18
|
+
Key,
|
|
19
|
+
KeyData,
|
|
20
|
+
KeyDataWrapper,
|
|
21
|
+
KeysDataWrapper,
|
|
22
|
+
)
|
|
17
23
|
|
|
18
24
|
if TYPE_CHECKING:
|
|
19
25
|
from typing_extensions import Self
|
|
@@ -89,6 +95,20 @@ class OpenRouterClient:
|
|
|
89
95
|
response = await self._request(METH_GET, "key")
|
|
90
96
|
return KeyDataWrapper.from_json(response).data
|
|
91
97
|
|
|
98
|
+
async def get_keys(self) -> list[Key]:
|
|
99
|
+
"""Get all keys."""
|
|
100
|
+
response = await self._request(METH_GET, "keys")
|
|
101
|
+
return KeysDataWrapper.from_json(response).data
|
|
102
|
+
|
|
103
|
+
async def create_key(self, name: str, limit: float | None = None) -> Key:
|
|
104
|
+
"""Create a new key."""
|
|
105
|
+
data: dict[str, Any] = {"name": name}
|
|
106
|
+
if limit is not None:
|
|
107
|
+
data["limit"] = limit
|
|
108
|
+
|
|
109
|
+
response = await self._request(METH_POST, "keys", data=data)
|
|
110
|
+
return CreateKeyDataWrapper.from_json(response).data
|
|
111
|
+
|
|
92
112
|
async def close(self) -> None:
|
|
93
113
|
"""Close open client session."""
|
|
94
114
|
if self.session and self._close_session:
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"""Models for OpenRouter."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
|
|
7
|
-
from mashumaro.mixins.orjson import DataClassORJSONMixin
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@dataclass
|
|
11
|
-
class KeyDataWrapper(DataClassORJSONMixin):
|
|
12
|
-
"""Wrapper for OpenRouter key data."""
|
|
13
|
-
|
|
14
|
-
data: KeyData
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@dataclass
|
|
18
|
-
class KeyData(DataClassORJSONMixin):
|
|
19
|
-
"""The OpenRouter key data."""
|
|
20
|
-
|
|
21
|
-
label: str
|
|
22
|
-
usage: int
|
|
23
|
-
is_provisioning_key: bool
|
|
24
|
-
limit_remaining: int | None
|
|
25
|
-
is_free_tier: bool
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|