Skip to content

Commit 945b307

Browse files
committed
feat: simplify api
1 parent 0e3f99d commit 945b307

28 files changed

Lines changed: 275 additions & 263 deletions

File tree

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ pip install replane[async]
3030
### Synchronous Client
3131

3232
```python
33-
from replane import SyncReplaneClient
33+
from replane import Replane
3434

3535
# Using context manager (recommended)
36-
with SyncReplaneClient(
36+
with Replane(
3737
base_url="https://replane.example.com",
3838
sdk_key="sk_live_...",
3939
) as client:
@@ -55,9 +55,9 @@ with SyncReplaneClient(
5555
Requires `pip install replane[async]`:
5656

5757
```python
58-
from replane import AsyncReplaneClient
58+
from replane import AsyncReplane
5959

60-
async with AsyncReplaneClient(
60+
async with AsyncReplane(
6161
base_url="https://replane.example.com",
6262
sdk_key="sk_live_...",
6363
) as client:
@@ -73,7 +73,7 @@ async with AsyncReplaneClient(
7373
Both clients accept the same configuration:
7474

7575
```python
76-
client = SyncReplaneClient(
76+
client = Replane(
7777
base_url="https://replane.example.com",
7878
sdk_key="sk_live_...",
7979

@@ -246,15 +246,15 @@ If you prefer not to use context managers:
246246

247247
```python
248248
# Sync
249-
client = SyncReplaneClient(base_url="...", sdk_key="...")
249+
client = Replane(base_url="...", sdk_key="...")
250250
client.connect() # Blocks until initialized
251251
try:
252252
value = client.get("config")
253253
finally:
254254
client.close()
255255

256256
# Async
257-
client = AsyncReplaneClient(base_url="...", sdk_key="...")
257+
client = AsyncReplane(base_url="...", sdk_key="...")
258258
await client.connect()
259259
try:
260260
value = client.get("config")
@@ -269,14 +269,14 @@ finally:
269269
```python
270270
from contextlib import asynccontextmanager
271271
from fastapi import FastAPI, Depends
272-
from replane import AsyncReplaneClient
272+
from replane import AsyncReplane
273273

274-
client: AsyncReplaneClient | None = None
274+
client: AsyncReplane | None = None
275275

276276
@asynccontextmanager
277277
async def lifespan(app: FastAPI):
278278
global client
279-
client = AsyncReplaneClient(
279+
client = AsyncReplane(
280280
base_url="https://replane.example.com",
281281
sdk_key="sk_live_...",
282282
)
@@ -286,12 +286,12 @@ async def lifespan(app: FastAPI):
286286

287287
app = FastAPI(lifespan=lifespan)
288288

289-
def get_replane() -> AsyncReplaneClient:
289+
def get_replane() -> AsyncReplane:
290290
assert client is not None
291291
return client
292292

293293
@app.get("/items")
294-
async def get_items(replane: AsyncReplaneClient = Depends(get_replane)):
294+
async def get_items(replane: AsyncReplane = Depends(get_replane)):
295295
max_items = replane.get("max-items", context={"plan": "free"})
296296
return {"max_items": max_items}
297297
```
@@ -300,15 +300,15 @@ async def get_items(replane: AsyncReplaneClient = Depends(get_replane)):
300300

301301
```python
302302
from flask import Flask, g
303-
from replane import SyncReplaneClient
303+
from replane import Replane
304304

305305
app = Flask(__name__)
306-
replane_client: SyncReplaneClient | None = None
306+
replane_client: Replane | None = None
307307

308308
@app.before_first_request
309309
def init_replane():
310310
global replane_client
311-
replane_client = SyncReplaneClient(
311+
replane_client = Replane(
312312
base_url="https://replane.example.com",
313313
sdk_key="sk_live_...",
314314
)

docs/source/api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ This page provides detailed API documentation for the Replane Python SDK.
44

55
## Clients
66

7-
### SyncReplaneClient
7+
### Replane
88

99
```{eval-rst}
10-
.. autoclass:: replane.SyncReplaneClient
10+
.. autoclass:: replane.Replane
1111
:members:
1212
:undoc-members:
1313
:show-inheritance:
1414
```
1515

16-
### AsyncReplaneClient
16+
### AsyncReplane
1717

1818
```{eval-rst}
19-
.. autoclass:: replane.AsyncReplaneClient
19+
.. autoclass:: replane.AsyncReplane
2020
:members:
2121
:undoc-members:
2222
:show-inheritance:

docs/source/configuration.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ This page documents all configuration options for the Replane clients.
44

55
## Client Options
66

7-
Both `SyncReplaneClient` and `AsyncReplaneClient` accept the same configuration options:
7+
Both `Replane` and `AsyncReplane` accept the same configuration options:
88

99
```python
10-
from replane import SyncReplaneClient
10+
from replane import Replane
1111

12-
replane = SyncReplaneClient(
12+
replane = Replane(
1313
# Required
1414
base_url="https://replane.example.com",
1515
sdk_key="rp_...",
@@ -60,7 +60,7 @@ Default context applied to all `get()` calls. This is merged with any context pa
6060

6161
```python
6262
# Set default context
63-
replane = SyncReplaneClient(
63+
replane = Replane(
6464
...,
6565
context={
6666
"environment": "production",
@@ -83,7 +83,7 @@ value = replane.get("config-name", context={"user_id": "123"})
8383
Fallback values used when configs can't be loaded from the server. This is useful for resilience - your application can still function with sensible defaults if the Replane server is unavailable.
8484

8585
```python
86-
replane = SyncReplaneClient(
86+
replane = Replane(
8787
...,
8888
fallbacks={
8989
"rate-limit": 100,
@@ -104,7 +104,7 @@ Fallbacks are used in two scenarios:
104104
List of config names that must be present after initialization. If any required config is missing, initialization will fail with a `ConfigNotFoundError`.
105105

106106
```python
107-
replane = SyncReplaneClient(
107+
replane = Replane(
108108
...,
109109
required=["rate-limit", "feature-enabled"],
110110
)
@@ -120,7 +120,7 @@ This is useful for catching configuration errors early rather than at runtime.
120120
Timeout for individual HTTP requests to the Replane server.
121121

122122
```python
123-
replane = SyncReplaneClient(
123+
replane = Replane(
124124
...,
125125
request_timeout_ms=5000, # 5 seconds
126126
)
@@ -133,7 +133,7 @@ replane = SyncReplaneClient(
133133
Maximum time to wait for the client to initialize and receive configs from the server.
134134

135135
```python
136-
replane = SyncReplaneClient(
136+
replane = Replane(
137137
...,
138138
initialization_timeout_ms=10000, # 10 seconds
139139
)
@@ -148,7 +148,7 @@ If initialization times out, a `TimeoutError` is raised.
148148
Initial delay between retry attempts when the connection fails. The delay increases exponentially with each retry (up to 30 seconds max).
149149

150150
```python
151-
replane = SyncReplaneClient(
151+
replane = Replane(
152152
...,
153153
retry_delay_ms=500, # Start with 0.5 seconds
154154
)
@@ -161,7 +161,7 @@ replane = SyncReplaneClient(
161161
Maximum time without receiving any SSE events before the connection is considered stale and reconnected. The server sends periodic keepalive pings, so this timeout should be longer than the server's ping interval.
162162

163163
```python
164-
replane = SyncReplaneClient(
164+
replane = Replane(
165165
...,
166166
inactivity_timeout_ms=60000, # 60 seconds
167167
)
@@ -174,7 +174,7 @@ replane = SyncReplaneClient(
174174
Enable debug logging to see detailed information about all client activity. This is useful for troubleshooting connection issues, understanding when configs are loaded, and diagnosing override evaluation.
175175

176176
```python
177-
replane = SyncReplaneClient(
177+
replane = Replane(
178178
...,
179179
debug=True, # Enable debug logging
180180
)
@@ -191,7 +191,7 @@ When enabled, you'll see logs for:
191191

192192
Example output:
193193
```
194-
2024-01-15 10:30:00 [DEBUG] replane: Initializing SyncReplaneClient: base_url=https://replane.example.com, ...
194+
2024-01-15 10:30:00 [DEBUG] replane: Initializing Replane: base_url=https://replane.example.com, ...
195195
2024-01-15 10:30:00 [DEBUG] replane: connect() called, wait=True
196196
2024-01-15 10:30:00 [DEBUG] replane: Connecting to SSE: host=replane.example.com, port=443, https=True
197197
2024-01-15 10:30:00 [DEBUG] replane: Response status: 200 OK
@@ -207,7 +207,7 @@ If you prefer not to use context managers, you can manage the client lifecycle m
207207
### Sync Client
208208

209209
```python
210-
replane = SyncReplaneClient(base_url="...", sdk_key="...")
210+
replane = Replane(base_url="...", sdk_key="...")
211211

212212
# Connect and wait for initialization
213213
replane.connect() # Blocks until ready
@@ -232,7 +232,7 @@ replane.wait_for_init()
232232
### Async Client
233233

234234
```python
235-
replane = AsyncReplaneClient(base_url="...", sdk_key="...")
235+
replane = AsyncReplane(base_url="...", sdk_key="...")
236236

237237
await replane.connect()
238238

@@ -249,7 +249,7 @@ While the SDK doesn't read environment variables directly, a common pattern is:
249249
```python
250250
import os
251251

252-
replane = SyncReplaneClient(
252+
replane = Replane(
253253
base_url=os.environ["REPLANE_URL"],
254254
sdk_key=os.environ["REPLANE_SDK_KEY"],
255255
)

docs/source/errors.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ Each `ReplaneError` has a `code` attribute from the `ErrorCode` enum:
3939

4040
```python
4141
from replane import (
42-
SyncReplaneClient,
42+
Replane,
4343
ReplaneError,
4444
ConfigNotFoundError,
4545
TimeoutError,
4646
AuthenticationError,
4747
)
4848

4949
try:
50-
with SyncReplaneClient(
50+
with Replane(
5151
base_url="https://replane.example.com",
5252
sdk_key="rp_...",
5353
) as replane:
@@ -112,7 +112,7 @@ except ConfigNotFoundError as e:
112112
value = replane.get("config", default="fallback")
113113

114114
# With fallbacks during init
115-
replane = SyncReplaneClient(
115+
replane = Replane(
116116
...,
117117
fallbacks={"config": "fallback"},
118118
)
@@ -137,7 +137,7 @@ except TimeoutError as e:
137137
**Prevention:** Increase timeout values:
138138

139139
```python
140-
replane = SyncReplaneClient(
140+
replane = Replane(
141141
...,
142142
initialization_timeout_ms=10000, # 10 seconds
143143
request_timeout_ms=5000, # 5 seconds
@@ -190,7 +190,7 @@ Raised when attempting operations on a closed client.
190190
```python
191191
from replane import ClientClosedError
192192

193-
replane = SyncReplaneClient(...)
193+
replane = Replane(...)
194194
replane.connect()
195195
replane.close()
196196

@@ -207,7 +207,7 @@ Raised when the client hasn't finished initializing.
207207
```python
208208
from replane import NotInitializedError
209209

210-
replane = SyncReplaneClient(...)
210+
replane = Replane(...)
211211
replane.connect(wait=False) # Don't wait
212212

213213
try:
@@ -222,10 +222,10 @@ except NotInitializedError:
222222
Raised when using features that require optional dependencies.
223223

224224
```python
225-
from replane import AsyncReplaneClient, MissingDependencyError
225+
from replane import AsyncReplane, MissingDependencyError
226226

227227
try:
228-
replane = AsyncReplaneClient(...)
228+
replane = AsyncReplane(...)
229229
except MissingDependencyError as e:
230230
print(f"Missing: {e.dependency}")
231231
print(f"Install with: pip install replane[async]")

0 commit comments

Comments
 (0)