python-open-router 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
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/__init__.py +14 -0
- python_open_router/models.py +33 -0
- python_open_router/open_router.py +22 -2
- {python_open_router-0.1.0.dist-info → python_open_router-0.2.0.dist-info}/METADATA +1 -1
- python_open_router-0.2.0.dist-info/RECORD +9 -0
- python_open_router-0.1.0.dist-info/RECORD +0 -9
- {python_open_router-0.1.0.dist-info → python_open_router-0.2.0.dist-info}/LICENSE.md +0 -0
- {python_open_router-0.1.0.dist-info → python_open_router-0.2.0.dist-info}/WHEEL +0 -0
python_open_router/__init__.py
CHANGED
|
@@ -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",
|
python_open_router/models.py
CHANGED
|
@@ -23,3 +23,36 @@ class KeyData(DataClassORJSONMixin):
|
|
|
23
23
|
is_provisioning_key: bool
|
|
24
24
|
limit_remaining: int | None
|
|
25
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:
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
python_open_router/__init__.py,sha256=dmD0nHFaJzzKYD7Q4Ltm9p46uBhAOLpPTnWVyH_KHH8,640
|
|
2
|
+
python_open_router/exceptions.py,sha256=68nskqNdXNMIK4iA1XOE1E5P5rbhAf27DDACkk-ZVwU,312
|
|
3
|
+
python_open_router/models.py,sha256=qIKy3bqx-RnwlbwV4kgTPuDkbII4xPq2PE3gA8mShwo,999
|
|
4
|
+
python_open_router/open_router.py,sha256=WOJtZ40l3dv8_GGWRV1caN--KAgv0g0KfNdl-KzGGLM,3909
|
|
5
|
+
python_open_router/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
python_open_router-0.2.0.dist-info/LICENSE.md,sha256=Xbw7n2Ic30r4j8_MDNND4ss_sdoj9IGeIkEWc2Hsfs8,1077
|
|
7
|
+
python_open_router-0.2.0.dist-info/METADATA,sha256=iYrSXHhOj1w-vHE51V3JZoIdNcjrfkedqw-wuILzYVg,6030
|
|
8
|
+
python_open_router-0.2.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
9
|
+
python_open_router-0.2.0.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
python_open_router/__init__.py,sha256=qWLg-1XHDTgXR7AGOzVjxQ2amINWgwTnMrRe77WFRXw,376
|
|
2
|
-
python_open_router/exceptions.py,sha256=68nskqNdXNMIK4iA1XOE1E5P5rbhAf27DDACkk-ZVwU,312
|
|
3
|
-
python_open_router/models.py,sha256=z-SMl13PAGRyQ_83zXlU7US0teNqxfc4ArTm0ain-zs,478
|
|
4
|
-
python_open_router/open_router.py,sha256=mVcNVZcSEcD5csllZes3RlKa7ReWEQXJf625M-so6Mo,3292
|
|
5
|
-
python_open_router/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
python_open_router-0.1.0.dist-info/LICENSE.md,sha256=Xbw7n2Ic30r4j8_MDNND4ss_sdoj9IGeIkEWc2Hsfs8,1077
|
|
7
|
-
python_open_router-0.1.0.dist-info/METADATA,sha256=KFnz6IFqokjCanKGMC6GmT3hzA53fdjc2JdinQU7OH4,6030
|
|
8
|
-
python_open_router-0.1.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
9
|
-
python_open_router-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|