You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds configurable state directory to client initialization (#6)
TL;DR
-----
Enables custom state directory configuration through an optional
parameter
Details
-------
Adds an optional `state_directory` parameter to both
`ReplicatedClient` and `AsyncReplicatedClient` to support scenarios
where the OS-standard location is ephemeral. When omitted, the
parameter defaults to None and the SDK uses existing platform-specific
logic unchanged. When provided, the SDK normalizes the path by
expanding tilde notation and resolving relative paths to absolute
ones, ensuring consistent behavior across different path styles.
This enhancement unblocks containerized deployments that need explicit
volume mount points, enables proper test isolation without filesystem
pollution, and supports multi-tenant architectures where state must
remain separate between customers. The implementation maintains the
SDK's silent failure philosophy for state operations, ensuring custom
directories integrate seamlessly with existing error handling
patterns.
Copy file name to clipboardExpand all lines: API_REFERENCE.md
+28-5Lines changed: 28 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,15 +56,17 @@ ReplicatedClient(
56
56
publishable_key: str,
57
57
app_slug: str,
58
58
base_url: str="https://replicated.app",
59
-
timeout: float=30.0
59
+
timeout: float=30.0,
60
+
state_directory: Optional[str] =None
60
61
)
61
62
```
62
63
63
64
**Parameters:**
64
65
-`publishable_key`: Your publishable API key from the Vendor Portal
65
66
-`app_slug`: Your application slug
66
-
-`base_url`: Base URL for the API (optional)
67
-
-`timeout`: Request timeout in seconds (optional)
67
+
-`base_url`: Base URL for the API (optional, defaults to "https://replicated.app")
68
+
-`timeout`: Request timeout in seconds (optional, defaults to 30.0)
69
+
-`state_directory`: Custom directory for state storage (optional). If not provided, uses platform-specific defaults. Supports `~` expansion and relative paths.
68
70
69
71
#### Methods
70
72
@@ -160,11 +162,32 @@ The SDK automatically manages local state for:
160
162
161
163
### State Directory
162
164
163
-
State is stored in platform-specific directories:
165
+
State is stored in platform-specific directories by default:
You can override the state directory by providing the `state_directory` parameter:
171
+
172
+
```python
173
+
client = ReplicatedClient(
174
+
publishable_key="...",
175
+
app_slug="my-app",
176
+
state_directory="/custom/path/to/state"
177
+
)
178
+
```
179
+
180
+
**Path Handling:**
181
+
- The SDK automatically expands `~` to your home directory
182
+
- Relative paths are resolved to absolute paths
183
+
- The directory will be created automatically if it doesn't exist
184
+
185
+
**Use Cases for Custom Directories:**
186
+
-**Testing:** Use temporary directories for isolated test runs
187
+
-**Containers:** Mount persistent volumes at custom paths
188
+
-**Multi-tenant:** Isolate state per tenant in separate directories
189
+
-**Development:** Use project-local directories for development state
190
+
168
191
## Machine Fingerprinting
169
192
170
193
The SDK generates unique machine fingerprints using:
@@ -207,4 +230,4 @@ async with AsyncReplicatedClient(...) as client:
207
230
208
231
## Thread Safety
209
232
210
-
The synchronous client creates a new HTTP client per request and is thread-safe. For high-concurrency applications, consider using the async client with a single event loop.
233
+
The synchronous client creates a new HTTP client per request and is thread-safe. For high-concurrency applications, consider using the async client with a single event loop.
0 commit comments