redchamber-world-api-client 1.1.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.
- redchamber_world_api_client/__init__.py +13 -0
- redchamber_world_api_client/api/__init__.py +1 -0
- redchamber_world_api_client/api/assets.py +26 -0
- redchamber_world_api_client/api/store.py +46 -0
- redchamber_world_api_client/api/worlds.py +43 -0
- redchamber_world_api_client/client.py +185 -0
- redchamber_world_api_client/exceptions.py +53 -0
- redchamber_world_api_client/models.py +93 -0
- redchamber_world_api_client/py.typed +0 -0
- redchamber_world_api_client-1.1.0.dist-info/METADATA +108 -0
- redchamber_world_api_client-1.1.0.dist-info/RECORD +14 -0
- redchamber_world_api_client-1.1.0.dist-info/WHEEL +5 -0
- redchamber_world_api_client-1.1.0.dist-info/licenses/LICENSE +23 -0
- redchamber_world_api_client-1.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""The RedChamber World API client for Python"""
|
|
2
|
+
|
|
3
|
+
from .client import RedChamberClient
|
|
4
|
+
from .exceptions import AuthenticationError, RateLimitError, RedChamberError, ValidationError
|
|
5
|
+
|
|
6
|
+
__version__ = "1.1.0"
|
|
7
|
+
__all__ = [
|
|
8
|
+
"RedChamberClient",
|
|
9
|
+
"RedChamberError",
|
|
10
|
+
"AuthenticationError",
|
|
11
|
+
"RateLimitError",
|
|
12
|
+
"ValidationError",
|
|
13
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""API Modules"""
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""API: assets"""
|
|
2
|
+
|
|
3
|
+
from ..models import PublicAssetList
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AssetsAPI:
|
|
7
|
+
"""API endpoints for assets"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, client):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
def list_assets(self) -> PublicAssetList:
|
|
13
|
+
"""
|
|
14
|
+
List your assets
|
|
15
|
+
|
|
16
|
+
Your asset library (metadata only), newest first.
|
|
17
|
+
"""
|
|
18
|
+
path = "/api/v1/public/assets"
|
|
19
|
+
answer = self._client._request(
|
|
20
|
+
method="GET",
|
|
21
|
+
path=path,
|
|
22
|
+
params=None,
|
|
23
|
+
json=None,
|
|
24
|
+
)
|
|
25
|
+
return self._client._model(answer, PublicAssetList)
|
|
26
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""API: store"""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
|
|
6
|
+
from ..models import PublicListingList, PublicSaleList
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class StoreAPI:
|
|
10
|
+
"""API endpoints for store"""
|
|
11
|
+
|
|
12
|
+
def __init__(self, client):
|
|
13
|
+
self._client = client
|
|
14
|
+
|
|
15
|
+
def list_listings(self, page: Optional[int] = None, limit: Optional[int] = None) -> PublicListingList:
|
|
16
|
+
"""
|
|
17
|
+
List your store listings
|
|
18
|
+
|
|
19
|
+
Your creator listings, at any moderation state (a held one says why).
|
|
20
|
+
"""
|
|
21
|
+
path = "/api/v1/public/store/listings"
|
|
22
|
+
answer = self._client._request(
|
|
23
|
+
method="GET",
|
|
24
|
+
path=path,
|
|
25
|
+
params={"page": page, "limit": limit},
|
|
26
|
+
json=None,
|
|
27
|
+
)
|
|
28
|
+
return self._client._model(answer, PublicListingList)
|
|
29
|
+
|
|
30
|
+
def list_sales(self, limit: Optional[int] = None, after: Optional[UUID] = None) -> PublicSaleList:
|
|
31
|
+
"""
|
|
32
|
+
List your store sales
|
|
33
|
+
|
|
34
|
+
Each sale of your listings that stands (a delivered order not taken back with its money
|
|
35
|
+
reversed), in order-id order, a page at a time after ``after`` (``next_after`` of the
|
|
36
|
+
previous page).
|
|
37
|
+
"""
|
|
38
|
+
path = "/api/v1/public/store/sales"
|
|
39
|
+
answer = self._client._request(
|
|
40
|
+
method="GET",
|
|
41
|
+
path=path,
|
|
42
|
+
params={"limit": limit, "after": after},
|
|
43
|
+
json=None,
|
|
44
|
+
)
|
|
45
|
+
return self._client._model(answer, PublicSaleList)
|
|
46
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""API: worlds"""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from ..models import PublicWorldList
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class WorldsAPI:
|
|
9
|
+
"""API endpoints for worlds"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, client):
|
|
12
|
+
self._client = client
|
|
13
|
+
|
|
14
|
+
def list_worlds(self, skip: Optional[int] = None, limit: Optional[int] = None) -> PublicWorldList:
|
|
15
|
+
"""
|
|
16
|
+
List your worlds
|
|
17
|
+
|
|
18
|
+
Every world you own — public and private alike — newest first.
|
|
19
|
+
"""
|
|
20
|
+
path = "/api/v1/public/worlds"
|
|
21
|
+
answer = self._client._request(
|
|
22
|
+
method="GET",
|
|
23
|
+
path=path,
|
|
24
|
+
params={"skip": skip, "limit": limit},
|
|
25
|
+
json=None,
|
|
26
|
+
)
|
|
27
|
+
return self._client._model(answer, PublicWorldList)
|
|
28
|
+
|
|
29
|
+
def search_worlds(self, q: str, skip: Optional[int] = None, limit: Optional[int] = None) -> PublicWorldList:
|
|
30
|
+
"""
|
|
31
|
+
Search public worlds
|
|
32
|
+
|
|
33
|
+
Public worlds whose name, description or location contains ``q``, newest first.
|
|
34
|
+
"""
|
|
35
|
+
path = "/api/v1/public/worlds/search"
|
|
36
|
+
answer = self._client._request(
|
|
37
|
+
method="GET",
|
|
38
|
+
path=path,
|
|
39
|
+
params={"q": q, "skip": skip, "limit": limit},
|
|
40
|
+
json=None,
|
|
41
|
+
)
|
|
42
|
+
return self._client._model(answer, PublicWorldList)
|
|
43
|
+
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"""The client class of the RedChamber World API client for Python."""
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from datetime import date, datetime
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
from typing import Any, Dict, List, Optional, Type, TypeVar
|
|
7
|
+
from uuid import UUID
|
|
8
|
+
from .exceptions import AuthenticationError, RateLimitError, RedChamberError, ValidationError
|
|
9
|
+
|
|
10
|
+
from .api.worlds import WorldsAPI
|
|
11
|
+
from .api.assets import AssetsAPI
|
|
12
|
+
from .api.store import StoreAPI
|
|
13
|
+
|
|
14
|
+
#: what the library's error says of an answer that is not of the type a method declares for it
|
|
15
|
+
UNEXPECTED_ANSWER = "The API's answer is not what this version of the library expects"
|
|
16
|
+
|
|
17
|
+
#: a model of the library: what a method that declares one returns
|
|
18
|
+
Answered = TypeVar("Answered", bound=BaseModel)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class RedChamberClient:
|
|
22
|
+
"""
|
|
23
|
+
RedChamber World API Client
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
client = RedChamberClient(api_key=os.environ["REDCHAMBER_API_KEY"])
|
|
27
|
+
result = client.worlds.list_worlds()
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
DEFAULT_BASE_URL = "https://api.redchamber.world"
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
api_key: str,
|
|
35
|
+
base_url: Optional[str] = None,
|
|
36
|
+
timeout: int = 30,
|
|
37
|
+
):
|
|
38
|
+
"""
|
|
39
|
+
Initialize the client.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
api_key: Your API key from the developer portal
|
|
43
|
+
base_url: Optional custom API base URL
|
|
44
|
+
timeout: Request timeout in seconds
|
|
45
|
+
"""
|
|
46
|
+
self.api_key = api_key
|
|
47
|
+
self.base_url = (base_url or self.DEFAULT_BASE_URL).rstrip("/")
|
|
48
|
+
self.timeout = timeout
|
|
49
|
+
self.session = requests.Session()
|
|
50
|
+
self.session.headers.update({
|
|
51
|
+
"X-API-Key": api_key,
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
"User-Agent": "redchamber-python/1.1.0",
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
# Initialize API modules
|
|
57
|
+
self.worlds = WorldsAPI(self)
|
|
58
|
+
self.assets = AssetsAPI(self)
|
|
59
|
+
self.store = StoreAPI(self)
|
|
60
|
+
|
|
61
|
+
def _request(
|
|
62
|
+
self,
|
|
63
|
+
method: str,
|
|
64
|
+
path: str,
|
|
65
|
+
params: Optional[Dict[str, Any]] = None,
|
|
66
|
+
json: Optional[Dict[str, Any]] = None,
|
|
67
|
+
) -> requests.Response:
|
|
68
|
+
"""Make an API request: the answer, or the error of a request the API refused"""
|
|
69
|
+
url = f"{self.base_url}{path}"
|
|
70
|
+
if params is not None:
|
|
71
|
+
params = {name: self._text(value) for name, value in params.items()}
|
|
72
|
+
|
|
73
|
+
response = self.session.request(
|
|
74
|
+
method=method,
|
|
75
|
+
url=url,
|
|
76
|
+
params=params,
|
|
77
|
+
json=json,
|
|
78
|
+
timeout=self.timeout,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
if not response.ok:
|
|
82
|
+
raise self._refusal(response)
|
|
83
|
+
|
|
84
|
+
return response
|
|
85
|
+
|
|
86
|
+
@staticmethod
|
|
87
|
+
def _text(value: Any) -> Any:
|
|
88
|
+
"""A value of an argument as the request carries it: a date or a time in ISO 8601, a
|
|
89
|
+
UUID as its text; any other value as it is"""
|
|
90
|
+
if isinstance(value, (date, datetime)):
|
|
91
|
+
return value.isoformat()
|
|
92
|
+
if isinstance(value, UUID):
|
|
93
|
+
return str(value)
|
|
94
|
+
return value
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def _body(response: requests.Response) -> Any:
|
|
98
|
+
"""An answer's JSON body as data — None when it has no body or its body is not JSON"""
|
|
99
|
+
try:
|
|
100
|
+
return response.json()
|
|
101
|
+
except ValueError:
|
|
102
|
+
return None
|
|
103
|
+
|
|
104
|
+
def _unexpected(self, response: requests.Response) -> RedChamberError:
|
|
105
|
+
"""The error of an answer that is not what a method declares for it"""
|
|
106
|
+
return RedChamberError(
|
|
107
|
+
UNEXPECTED_ANSWER, response.status_code, body=self._body(response)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
def _data(self, response: requests.Response) -> Any:
|
|
111
|
+
"""The data of an answer the library declares no type for, as it arrived: JSON data when
|
|
112
|
+
the answer says it is JSON, its bytes when it says another type, None when it has no
|
|
113
|
+
body"""
|
|
114
|
+
if not response.content:
|
|
115
|
+
return None
|
|
116
|
+
if "json" not in response.headers.get("Content-Type", "").lower():
|
|
117
|
+
return response.content
|
|
118
|
+
try:
|
|
119
|
+
return response.json()
|
|
120
|
+
except ValueError as unreadable:
|
|
121
|
+
raise self._unexpected(response) from unreadable
|
|
122
|
+
|
|
123
|
+
def _model(self, response: requests.Response, model: Type[Answered]) -> Answered:
|
|
124
|
+
"""The answer as the library's ``model`` of it. An answer that does not fit the model
|
|
125
|
+
raises the library's own error, with what did not fit as its cause"""
|
|
126
|
+
try:
|
|
127
|
+
return model.model_validate(response.json())
|
|
128
|
+
except ValueError as unfit:
|
|
129
|
+
raise self._unexpected(response) from unfit
|
|
130
|
+
|
|
131
|
+
def _models(self, response: requests.Response, model: Type[Answered]) -> List[Answered]:
|
|
132
|
+
"""The answer as a list of the library's ``model``. An answer that is no list, or holds
|
|
133
|
+
a member that does not fit the model, raises the library's own error, with what did not
|
|
134
|
+
fit as its cause"""
|
|
135
|
+
try:
|
|
136
|
+
listed = response.json()
|
|
137
|
+
if not isinstance(listed, list):
|
|
138
|
+
raise ValueError("the answer is not a list")
|
|
139
|
+
return [model.model_validate(member) for member in listed]
|
|
140
|
+
except ValueError as unfit:
|
|
141
|
+
raise self._unexpected(response) from unfit
|
|
142
|
+
|
|
143
|
+
def _refusal(self, response: requests.Response) -> RedChamberError:
|
|
144
|
+
"""The error of an answer the API refused. Its message is the answer's own sentence
|
|
145
|
+
("message", else "detail" when that is a sentence), else the status alone; its code
|
|
146
|
+
is the answer's "error" when it names one. It carries the seconds of the answer's
|
|
147
|
+
"Retry-After" header when that is a number, and the answer's JSON body."""
|
|
148
|
+
status = response.status_code
|
|
149
|
+
body = self._body(response)
|
|
150
|
+
said = body if isinstance(body, dict) else {}
|
|
151
|
+
|
|
152
|
+
message = said.get("message")
|
|
153
|
+
if not isinstance(message, str) or not message:
|
|
154
|
+
message = said.get("detail")
|
|
155
|
+
if not isinstance(message, str) or not message:
|
|
156
|
+
message = f"HTTP {status}"
|
|
157
|
+
code = said.get("error") if isinstance(said.get("error"), str) else None
|
|
158
|
+
seconds = response.headers.get("Retry-After", "")
|
|
159
|
+
retry_after = int(seconds) if seconds.isdigit() else None
|
|
160
|
+
|
|
161
|
+
if status == 401:
|
|
162
|
+
return AuthenticationError(message, status, code, retry_after, body)
|
|
163
|
+
|
|
164
|
+
if status == 429:
|
|
165
|
+
return RateLimitError(message, status, code, retry_after, body)
|
|
166
|
+
|
|
167
|
+
if status == 422:
|
|
168
|
+
listed = said.get("errors")
|
|
169
|
+
errors = [
|
|
170
|
+
{
|
|
171
|
+
"field": fault["field"] if isinstance(fault.get("field"), str) else None,
|
|
172
|
+
"message": fault["message"] if isinstance(fault.get("message"), str) else "",
|
|
173
|
+
}
|
|
174
|
+
for fault in (listed if isinstance(listed, list) else [])
|
|
175
|
+
if isinstance(fault, dict)
|
|
176
|
+
]
|
|
177
|
+
named = "; ".join(
|
|
178
|
+
f"{fault['field']}: {fault['message']}" if fault["field"] else fault["message"]
|
|
179
|
+
for fault in errors
|
|
180
|
+
)
|
|
181
|
+
if named:
|
|
182
|
+
message = f"{message}: {named}"
|
|
183
|
+
return ValidationError(message, status, code, retry_after, body, errors=errors)
|
|
184
|
+
|
|
185
|
+
return RedChamberError(message, status, code, retry_after, body)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""The exceptions of the RedChamber World API client for Python"""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RedChamberError(Exception):
|
|
7
|
+
"""A request the API refused, or an answer that is not what this version of the library
|
|
8
|
+
expects: every error the client raises is this, or one of its three kinds below.
|
|
9
|
+
``message`` is the API's own sentence, ``status_code`` the answer's status and ``code`` the
|
|
10
|
+
API's error code when it names one. ``retry_after`` is the number of seconds the answer's
|
|
11
|
+
``Retry-After`` header says to wait — None when it has none — and ``body`` the answer's
|
|
12
|
+
JSON body as data — None when it has none: every fact the API sends with a refusal is
|
|
13
|
+
in it."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
message: str,
|
|
18
|
+
status_code: int,
|
|
19
|
+
code: Optional[str] = None,
|
|
20
|
+
retry_after: Optional[int] = None,
|
|
21
|
+
body: Any = None,
|
|
22
|
+
):
|
|
23
|
+
self.message = message
|
|
24
|
+
self.status_code = status_code
|
|
25
|
+
self.code = code
|
|
26
|
+
self.retry_after = retry_after
|
|
27
|
+
self.body = body
|
|
28
|
+
super().__init__(message)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class AuthenticationError(RedChamberError):
|
|
32
|
+
"""The API key is missing, invalid or expired (401)"""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class RateLimitError(RedChamberError):
|
|
36
|
+
"""Too many requests (429)"""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ValidationError(RedChamberError):
|
|
40
|
+
"""The API could not read the request (422). ``errors`` lists each fault: the ``field`` it
|
|
41
|
+
is about (None when the API names none) and its ``message``."""
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
message: str,
|
|
46
|
+
status_code: int,
|
|
47
|
+
code: Optional[str] = None,
|
|
48
|
+
retry_after: Optional[int] = None,
|
|
49
|
+
body: Any = None,
|
|
50
|
+
errors: Optional[List[Dict[str, Optional[str]]]] = None,
|
|
51
|
+
):
|
|
52
|
+
super().__init__(message, status_code, code, retry_after, body)
|
|
53
|
+
self.errors = errors or []
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""The models of the RedChamber World API client for Python"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from typing import List, Optional
|
|
7
|
+
from uuid import UUID
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PublicAsset(BaseModel):
|
|
13
|
+
"""An asset in the owner's library (metadata only — never a fetchable file URL)."""
|
|
14
|
+
id: UUID
|
|
15
|
+
name: Optional[str] = None
|
|
16
|
+
asset_type: str
|
|
17
|
+
content_type: Optional[str] = None
|
|
18
|
+
size_bytes: int
|
|
19
|
+
license: Optional[str] = None
|
|
20
|
+
source: str
|
|
21
|
+
created_at: Optional[datetime] = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class PublicAssetList(BaseModel):
|
|
25
|
+
"""PublicAssetList"""
|
|
26
|
+
assets: List[PublicAsset]
|
|
27
|
+
total: int
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class PublicListing(BaseModel):
|
|
31
|
+
"""One of the owner's creator listings in the store, at any moderation state."""
|
|
32
|
+
id: UUID
|
|
33
|
+
slug: str
|
|
34
|
+
name: str
|
|
35
|
+
product_type: Optional[str] = None
|
|
36
|
+
petal_price: Optional[int] = None
|
|
37
|
+
license: Optional[str] = None
|
|
38
|
+
moderation_status: Optional[str] = None
|
|
39
|
+
unpublish_reason: Optional[str] = None
|
|
40
|
+
held_by: Optional[List[str]] = None
|
|
41
|
+
is_active: bool
|
|
42
|
+
is_purchasable: bool
|
|
43
|
+
sold_count: int
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class PublicListingList(BaseModel):
|
|
47
|
+
"""PublicListingList"""
|
|
48
|
+
listings: List[PublicListing]
|
|
49
|
+
total: int
|
|
50
|
+
page: int
|
|
51
|
+
limit: int
|
|
52
|
+
has_more: bool
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class PublicSale(BaseModel):
|
|
56
|
+
"""A sale of one of the owner's listings that stands — a delivered order not taken back with
|
|
57
|
+
its money reversed. The creator's USD share of a sale is shown in the creator's payouts, not
|
|
58
|
+
in this answer."""
|
|
59
|
+
order_id: UUID
|
|
60
|
+
item_id: UUID
|
|
61
|
+
sold_at: datetime
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class PublicSaleList(BaseModel):
|
|
65
|
+
"""PublicSaleList"""
|
|
66
|
+
sales: List[PublicSale]
|
|
67
|
+
next_after: Optional[UUID] = None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class PublicWorld(BaseModel):
|
|
71
|
+
"""A world (the owner's view for their own worlds; the public view in search)."""
|
|
72
|
+
id: UUID
|
|
73
|
+
owner_id: UUID
|
|
74
|
+
name: str
|
|
75
|
+
description: Optional[str] = None
|
|
76
|
+
world_type: str
|
|
77
|
+
visibility: str
|
|
78
|
+
tags: List[str]
|
|
79
|
+
thumbnail_url: Optional[str] = None
|
|
80
|
+
is_published: bool
|
|
81
|
+
status: str
|
|
82
|
+
view_count: int
|
|
83
|
+
like_count: int
|
|
84
|
+
created_at: datetime
|
|
85
|
+
updated_at: datetime
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class PublicWorldList(BaseModel):
|
|
89
|
+
"""PublicWorldList"""
|
|
90
|
+
worlds: List[PublicWorld]
|
|
91
|
+
total: int
|
|
92
|
+
skip: int
|
|
93
|
+
limit: int
|
|
File without changes
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: redchamber-world-api-client
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: RedChamber World API client for Python
|
|
5
|
+
Author: RedChamber Team
|
|
6
|
+
License-Expression: LicenseRef-RedChamber-World-API-Client-License
|
|
7
|
+
Project-URL: Developer portal, https://redchamber.world/developer
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: requests>=2.28.0
|
|
15
|
+
Requires-Dist: pydantic>=2.0.0
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# RedChamber World API client for Python
|
|
19
|
+
|
|
20
|
+
The official RedChamber World API client for Python: the package `redchamber-world-api-client`, imported as `redchamber_world_api_client`.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
This library is on PyPI:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install redchamber-world-api-client
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import os
|
|
34
|
+
|
|
35
|
+
from redchamber_world_api_client import RedChamberClient
|
|
36
|
+
|
|
37
|
+
client = RedChamberClient(api_key=os.environ["REDCHAMBER_API_KEY"])
|
|
38
|
+
|
|
39
|
+
# List your worlds
|
|
40
|
+
list_worlds = client.worlds.list_worlds()
|
|
41
|
+
print(list_worlds)
|
|
42
|
+
|
|
43
|
+
# Search public worlds
|
|
44
|
+
search_worlds = client.worlds.search_worlds(q="example")
|
|
45
|
+
print(search_worlds)
|
|
46
|
+
|
|
47
|
+
# List your store sales
|
|
48
|
+
list_sales = client.store.list_sales()
|
|
49
|
+
print(list_sales)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A call returns one of the models of `redchamber_world_api_client/models.py`, built from the API's answer.
|
|
53
|
+
|
|
54
|
+
## Authentication
|
|
55
|
+
|
|
56
|
+
Every call needs an API key: create one in the [developer portal](https://redchamber.world/developer). The client sends it in
|
|
57
|
+
the `X-API-Key` header; the samples read it from the environment variable `REDCHAMBER_API_KEY`.
|
|
58
|
+
Each call needs one of the key's scopes. The library's groups, as the API's description words them:
|
|
59
|
+
|
|
60
|
+
- `client.worlds` — Your worlds, and public world search (worlds:read)
|
|
61
|
+
- `client.assets` — Your asset library (content:read)
|
|
62
|
+
- `client.store` — Your store listings (content:read) and sales (analytics:read)
|
|
63
|
+
|
|
64
|
+
## Error Handling
|
|
65
|
+
|
|
66
|
+
A call the API refuses gives one of the library's errors. Each is a `RedChamberError` and carries
|
|
67
|
+
the API's own sentence, the answer's status code and — when the API names one — its error code:
|
|
68
|
+
`AuthenticationError` (401), `RateLimitError` (429), `ValidationError` (422, with each field's
|
|
69
|
+
fault), and `RedChamberError` itself for every other refusal.
|
|
70
|
+
|
|
71
|
+
Every error also has `retry_after` — the seconds the answer's `Retry-After` header says to wait, or `None` — and `body`, the answer's JSON body as data, or `None`: every fact the API sends with a refusal is read from it.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import os
|
|
75
|
+
|
|
76
|
+
from redchamber_world_api_client import (
|
|
77
|
+
AuthenticationError,
|
|
78
|
+
RateLimitError,
|
|
79
|
+
RedChamberClient,
|
|
80
|
+
RedChamberError,
|
|
81
|
+
ValidationError,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
client = RedChamberClient(api_key=os.environ["REDCHAMBER_API_KEY"])
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
result = client.worlds.list_worlds()
|
|
88
|
+
print(result)
|
|
89
|
+
except AuthenticationError:
|
|
90
|
+
print("Invalid API key")
|
|
91
|
+
except RateLimitError as error:
|
|
92
|
+
print(f"Rate limited: {error}")
|
|
93
|
+
except ValidationError as error:
|
|
94
|
+
for fault in error.errors:
|
|
95
|
+
print(f"{fault['field']}: {fault['message']}")
|
|
96
|
+
except RedChamberError as error:
|
|
97
|
+
print(f"Refused ({error.status_code}): {error}")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
An answer that is not what this version of the library expects raises a `RedChamberError` that says so, with what did not fit as its cause.
|
|
101
|
+
|
|
102
|
+
## Documentation
|
|
103
|
+
|
|
104
|
+
The API's documentation: [https://redchamber.world/developer/documentation](https://redchamber.world/developer/documentation)
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
RedChamber World API Client License — see the LICENSE file.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
redchamber_world_api_client/__init__.py,sha256=uupfMbNYnxQqpDs_912vI78yFBxu6QUkmXUek4byExc,337
|
|
2
|
+
redchamber_world_api_client/client.py,sha256=1_ExqSYRDZTG0weJDq4O5KfI4hV8a1CxTEQYQ5Wd3tw,7192
|
|
3
|
+
redchamber_world_api_client/exceptions.py,sha256=5jSm1aUNYst7zmz7H_39U7BX7KM-IhTTAGVOH-WVkDo,1854
|
|
4
|
+
redchamber_world_api_client/models.py,sha256=9YPZHQg7Ikm9b3yYsLu3hZVxOBy_gjTKfklBMYePj48,2282
|
|
5
|
+
redchamber_world_api_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
redchamber_world_api_client/api/__init__.py,sha256=2OjrARcbBwn6N1Hl_71Jc4Dj_WlZh3f13tsoSvOPe9w,17
|
|
7
|
+
redchamber_world_api_client/api/assets.py,sha256=7zgo6imIRDDGetfLZOkQbVOs7bWpAH15EyrQotGBhjw,575
|
|
8
|
+
redchamber_world_api_client/api/store.py,sha256=ykdc3m1NUuk6712B2z7aRmuiSaFJ6WzkDY8Ala2Q3fc,1401
|
|
9
|
+
redchamber_world_api_client/api/worlds.py,sha256=xPGMmpYd_hS25PgH6E-JeOvVfJvw6kG72kGpEDdaEYg,1247
|
|
10
|
+
redchamber_world_api_client-1.1.0.dist-info/licenses/LICENSE,sha256=Gw3ETW2X4z7jhfaxrvo8css_tyYooH_1yKTYmHE5ac8,1097
|
|
11
|
+
redchamber_world_api_client-1.1.0.dist-info/METADATA,sha256=JbhV0Msr_eK94Nx1c-0sUEOTDqxZsPUaf0QGznFA0mM,3572
|
|
12
|
+
redchamber_world_api_client-1.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
13
|
+
redchamber_world_api_client-1.1.0.dist-info/top_level.txt,sha256=nPKaWjEgur_wFFdY_GruCDl5Q5jaKK12-BIgu9a-wkM,28
|
|
14
|
+
redchamber_world_api_client-1.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
RedChamber World API Client License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RedChamber World. All rights reserved.
|
|
4
|
+
|
|
5
|
+
You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
|
|
6
|
+
copy, modify, and distribute this software, in source code or binary form,
|
|
7
|
+
solely for use in connection with the web services and APIs provided by the
|
|
8
|
+
RedChamber World platform (https://redchamber.world). No other use is
|
|
9
|
+
permitted.
|
|
10
|
+
|
|
11
|
+
Your use of this software with the RedChamber World platform is subject to the
|
|
12
|
+
platform's terms (https://redchamber.world/terms).
|
|
13
|
+
|
|
14
|
+
This copyright notice shall be included in all copies or substantial portions
|
|
15
|
+
of the software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
redchamber_world_api_client
|