Skip to content

Commit 6281caf

Browse files
crdantclaude
andcommitted
Documents custom state directory feature and use cases
Updates README.md with practical examples showing how to use custom state directories with absolute paths, tilde expansion, and relative paths. Adds API_REFERENCE.md documentation detailing the state_directory parameter, path handling behavior, and common use cases (testing, containers, multi-tenant apps, development environments). Clarifies that this feature is optional and defaults maintain backward compatibility with platform-specific directories. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1f64e92 commit 6281caf

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

API_REFERENCE.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ ReplicatedClient(
5656
publishable_key: str,
5757
app_slug: str,
5858
base_url: str = "https://replicated.app",
59-
timeout: float = 30.0
59+
timeout: float = 30.0,
60+
state_directory: Optional[str] = None
6061
)
6162
```
6263

6364
**Parameters:**
6465
- `publishable_key`: Your publishable API key from the Vendor Portal
6566
- `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.
6870

6971
#### Methods
7072

@@ -76,7 +78,7 @@ The asynchronous version of ReplicatedClient with identical API but requiring `a
7678

7779
#### Constructor
7880

79-
Same parameters as `ReplicatedClient`.
81+
Same parameters as `ReplicatedClient`, including the optional `state_directory`.
8082

8183
#### Context Manager
8284

@@ -160,11 +162,32 @@ The SDK automatically manages local state for:
160162

161163
### State Directory
162164

163-
State is stored in platform-specific directories:
165+
State is stored in platform-specific directories by default:
164166
- **macOS:** `~/Library/Application Support/Replicated/<app_slug>`
165167
- **Linux:** `${XDG_STATE_HOME:-~/.local/state}/replicated/<app_slug>`
166168
- **Windows:** `%APPDATA%\Replicated\<app_slug>`
167169

170+
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+
168191
## Machine Fingerprinting
169192

170193
The SDK generates unique machine fingerprints using:

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ instance.set_status(InstanceStatus.RUNNING)
3434
instance.set_version("1.2.0")
3535
```
3636

37+
### Custom State Directory
38+
39+
By default, the SDK stores state in platform-specific directories. You can override this for testing, containerization, or custom deployments:
40+
41+
```python
42+
from replicated import ReplicatedClient
43+
44+
# Use a custom directory (supports ~ and relative paths)
45+
client = ReplicatedClient(
46+
publishable_key="replicated_pk_...",
47+
app_slug="my-app",
48+
state_directory="/var/lib/my-app/replicated-state"
49+
)
50+
51+
# Or use a relative path (will be resolved to absolute)
52+
client = ReplicatedClient(
53+
publishable_key="replicated_pk_...",
54+
app_slug="my-app",
55+
state_directory="./local-state"
56+
)
57+
```
58+
59+
**When to use custom state directories:**
60+
- Testing with temporary directories
61+
- Docker containers with mounted volumes
62+
- Multi-tenant applications requiring isolated state
63+
- Development with project-local state
64+
3765
### Async Example
3866

3967
```python

0 commit comments

Comments
 (0)