Skip to content

Commit 5682f40

Browse files
docs: better docs (#20)
1 parent 63fa4cd commit 5682f40

10 files changed

Lines changed: 560 additions & 13 deletions

README.md

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,109 @@
22
<img src="https://github.com/Use-Tusk/drift-python-sdk/raw/main/images/tusk-banner.png" alt="Tusk Drift Banner">
33
</p>
44

5+
<p align="center">
6+
<a href="https://pypi.org/project/tusk-drift-python-sdk/"><img src="https://img.shields.io/pypi/v/tusk-drift-python-sdk" alt="PyPI version"></a>
7+
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="License: Apache 2.0"></a>
8+
<a href="https://github.com/Use-Tusk/drift-python-sdk/commits/main/"><img src="https://img.shields.io/github/last-commit/Use-Tusk/drift-python-sdk" alt="GitHub last commit"></a>
9+
<a href="https://x.com/usetusk"><img src="https://img.shields.io/twitter/url?url=https%3A%2F%2Fx.com%2Fusetusk&style=flat&logo=x&label=Tusk&color=BF40BF" alt="Tusk X account"></a>
10+
<a href="https://join.slack.com/t/tusk-community/shared_invite/zt-3fve1s7ie-NAAUn~UpHsf1m_2tdoGjsQ"><img src="https://img.shields.io/badge/slack-badge?style=flat&logo=slack&label=Tusk&color=BF40BF" alt="Tusk Community Slack"></a>
11+
</p>
12+
13+
The Python Tusk Drift SDK enables fast and deterministic API testing by capturing and replaying API calls made to/from your service. Automatically record real-world API calls, then replay them as tests using the [Tusk CLI](https://github.com/Use-Tusk/tusk-drift-cli) to find regressions. During replay, all outbound requests are intercepted with recorded data to ensure consistent behavior without side-effects.
14+
515
<div align="center">
616

7-
[![X URL](https://img.shields.io/twitter/url?url=https%3A%2F%2Fx.com%2Fusetusk&style=flat&logo=x&label=Tusk&color=BF40BF)](https://x.com/usetusk)
8-
[![Slack URL](https://img.shields.io/badge/slack-badge?style=flat&logo=slack&label=Tusk&color=BF40BF)](https://join.slack.com/t/tusk-community/shared_invite/zt-3fve1s7ie-NAAUn~UpHsf1m_2tdoGjsQ)
17+
![Demo](images/demo.gif)
18+
19+
<p><a href="https://github.com/Use-Tusk/drift-python-demo">Try it on a demo repo →</a></p>
920

1021
</div>
1122

12-
# Drift Python SDK
23+
## Documentation
24+
25+
For comprehensive guides and API reference, visit our [full documentation](https://docs.usetusk.ai/api-tests/installation#setup).
26+
27+
### SDK Guides
28+
29+
- [Initialization Guide](docs/initialization.md) - Set up the SDK in your Python application
30+
- [Environment Variables](docs/environment-variables.md) - Environment variables reference
31+
- [Quick Start Guide](docs/quickstart.md) - Record and replay your first trace
32+
33+
<div align="center">
34+
35+
![Tusk Drift Animated Diagram](images/tusk-drift-animated-diagram-light.gif#gh-light-mode-only)
36+
![Tusk Drift Animated Diagram](images/tusk-drift-animated-diagram-dark.gif#gh-dark-mode-only)
37+
38+
</div>
39+
40+
## Requirements
41+
42+
- Python 3.12+
1343

14-
Python SDK for Tusk Drift instrumentation and replay.
44+
Tusk Drift currently supports the following packages and versions:
45+
46+
- **Flask**: `flask>=2.0.0`
47+
- **FastAPI**: `fastapi>=0.68.0`
48+
- **Django**: `django>=3.2.0`
49+
- **Requests**: `requests` (all versions)
50+
- **HTTPX**: `httpx` (all versions)
51+
- **psycopg**: `psycopg>=3.0.0`, `psycopg2>=2.8.0`
52+
- **Redis**: `redis` (all versions)
53+
54+
If you're using packages or versions not listed above, please create an issue with the package + version you'd like an instrumentation for.
1555

1656
## Installation
1757

58+
### Step 1: Install the CLI
59+
60+
First, install and configure the Tusk Drift CLI by following our [CLI installation guide](https://github.com/Use-Tusk/tusk-drift-cli?tab=readme-ov-file#install). The CLI helps set up your Tusk configuration file and replays tests.
61+
62+
The wizard will eventually direct you back here when it's time to set up the SDK.
63+
64+
### Step 2: Install the SDK
65+
66+
After completing the CLI wizard, install the SDK:
67+
1868
```bash
1969
pip install tusk-drift-python-sdk
2070
```
2171

22-
### With Framework Support
72+
#### With Framework Support
2373

2474
```bash
25-
# Flask support
75+
# With Flask support
2676
pip install tusk-drift-python-sdk[flask]
2777

28-
# FastAPI support
78+
# With FastAPI support
2979
pip install tusk-drift-python-sdk[fastapi]
3080

31-
# Django support
81+
# With Django support
3282
pip install tusk-drift-python-sdk[django]
3383
```
3484

35-
## Requirements
85+
### Step 3: Initialize the SDK for your service
3686

37-
- Python 3.12+
87+
Refer to our [initialization guide](docs/initialization.md) to set up the SDK for your service.
88+
89+
### Step 4: Run Your First Test
90+
91+
Follow along our [quick start guide](docs/quickstart.md) to record and replay your first test!
92+
93+
## Troubleshooting
94+
95+
Having issues?
96+
97+
- Check our [initialization guide](docs/initialization.md) for common setup issues
98+
- Create an issue or reach us at [support@usetusk.ai](mailto:support@usetusk.ai).
99+
100+
## Community
101+
102+
Join our open source community on [Slack](https://join.slack.com/t/tusk-community/shared_invite/zt-3fve1s7ie-NAAUn~UpHsf1m_2tdoGjsQ).
38103

39104
## Contributing
40105

41-
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
106+
We appreciate feedback and contributions. See [CONTRIBUTING.md](/CONTRIBUTING.md).
42107

43108
## License
44109

45-
Apache License 2.0
110+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.

docs/environment-variables.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Environment Variables
2+
3+
This guide covers the environment variables that can be set when using the Tusk Drift SDK.
4+
5+
## TUSK_DRIFT_MODE
6+
7+
The `TUSK_DRIFT_MODE` environment variable controls how the SDK operates in your application.
8+
9+
### Available Modes
10+
11+
| Mode | Description | When to Use |
12+
| ---------- | ---------------------------------------------------- | -------------------------------------------------------------------------------------------- |
13+
| `RECORD` | Records traces for all instrumented operations | Set this in environments where you want to capture API traces (e.g., staging, production) |
14+
| `REPLAY` | Replays previously recorded traces | Automatically set by the Tusk CLI when running `tusk run` - you should NOT set this manually |
15+
| `DISABLED` | Disables all instrumentation and recording | Use when you want to completely disable Tusk with no performance impact |
16+
| Unset | Same as `DISABLED` - no instrumentation or recording | Default state when the variable is not set |
17+
18+
### Important Notes
19+
20+
**Recording Traces:**
21+
22+
- Set `TUSK_DRIFT_MODE=RECORD` in any environment where you want to record traces
23+
- This is typically staging, production, or local development environments
24+
- Traces will be saved according to your `recording` configuration in `.tusk/config.yaml`
25+
26+
**Replaying Traces:**
27+
28+
- `TUSK_DRIFT_MODE` is automatically set to `REPLAY` by the Tusk CLI when you run `tusk run`
29+
- **Do NOT** manually set `TUSK_DRIFT_MODE=REPLAY` in your application startup commands
30+
- The start command specified in your `.tusk/config.yaml` should NOT cause `TUSK_DRIFT_MODE` to be set to anything - the CLI handles this automatically
31+
32+
**Disabling Tusk:**
33+
34+
- If `TUSK_DRIFT_MODE` is unset or set to `DISABLED`, the SDK will not add any instrumentation
35+
- No data will be recorded and there should be **no performance impact**
36+
- This is useful for environments where you don't need Tusk functionality
37+
38+
### Examples
39+
40+
**Recording in development:**
41+
42+
```bash
43+
TUSK_DRIFT_MODE=RECORD python app.py
44+
```
45+
46+
**Recording in production (via environment variable):**
47+
48+
```bash
49+
# In your .env file or deployment configuration
50+
TUSK_DRIFT_MODE=RECORD
51+
```
52+
53+
**Start command in config.yaml (correct):**
54+
55+
```yaml
56+
# .tusk/config.yaml
57+
start_command: "python app.py" # Do NOT include TUSK_DRIFT_MODE here
58+
```
59+
60+
**Replaying traces (handled by CLI):**
61+
62+
```bash
63+
# The CLI automatically sets TUSK_DRIFT_MODE=REPLAY
64+
tusk run
65+
```
66+
67+
**Disabling Tusk:**
68+
69+
```bash
70+
# Either unset the variable or explicitly disable
71+
TUSK_DRIFT_MODE=DISABLED python app.py
72+
73+
# Or simply don't set it at all
74+
python app.py
75+
```
76+
77+
## TUSK_API_KEY
78+
79+
Your Tusk Drift API key, required when using Tusk Cloud for storing and managing traces.
80+
81+
- **Required:** Only if using Tusk Cloud (not needed for local-only trace storage)
82+
- **Where to get it:** [Tusk Drift Dashboard](https://usetusk.ai/app/settings/api-keys)
83+
84+
### How to Set
85+
86+
**For Recording:**
87+
88+
- Must be provided in the `TuskDrift.initialize()` call:
89+
90+
```python
91+
sdk = TuskDrift.initialize(
92+
api_key=os.environ.get("TUSK_API_KEY"), # or hard-coded for non-production
93+
# ... other options
94+
)
95+
```
96+
97+
**For Replay:**
98+
99+
- Can be set as an environment variable:
100+
101+
```bash
102+
TUSK_API_KEY=your-api-key-here tusk run
103+
```
104+
105+
- Or use the Tusk CLI login command (recommended):
106+
107+
```bash
108+
tusk auth login
109+
```
110+
111+
This will securely store your auth key for future replay sessions.
112+
113+
## TUSK_SAMPLING_RATE
114+
115+
Controls what percentage of requests are recorded during trace collection.
116+
117+
- **Type:** Number between 0.0 and 1.0
118+
- **Default:** 1.0 (100% of requests)
119+
- **Precedence:** This environment variable is overridden by the `sampling_rate` parameter in `TuskDrift.initialize()`, but takes precedence over the `sampling_rate` setting in `.tusk/config.yaml`
120+
121+
**Examples:**
122+
123+
```bash
124+
# Record all requests (100%)
125+
TUSK_SAMPLING_RATE=1.0 python app.py
126+
127+
# Record 10% of requests
128+
TUSK_SAMPLING_RATE=0.1 python app.py
129+
```
130+
131+
For more details on sampling rate configuration methods and precedence, see the [Initialization Guide](./initialization.md#configure-sampling-rate).
132+
133+
## Connection Variables
134+
135+
These variables configure how the SDK connects to the Tusk CLI during replay:
136+
137+
| Variable | Description | Default |
138+
| ------------------ | ----------------------------------- | ------------------------- |
139+
| `TUSK_MOCK_HOST` | CLI host for TCP connection | - |
140+
| `TUSK_MOCK_PORT` | CLI port for TCP connection | - |
141+
| `TUSK_MOCK_SOCKET` | Unix socket path for CLI connection | `/tmp/tusk-connect.sock` |
142+
143+
These are typically set automatically by the Tusk CLI and do not need to be configured manually.
144+
145+
---
146+
147+
## Related Documentation
148+
149+
- [Initialization Guide](./initialization.md) - SDK initialization parameters and config file settings
150+
- [Quick Start Guide](./quickstart.md) - Record and replay your first trace

0 commit comments

Comments
 (0)