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
This document explains how Rust acceleration works in the Python SDK, how to enable it, and what fallback behavior to expect.
4
+
5
+
## Overview
6
+
7
+
The SDK can offload selected hot-path logic to Rust through optional Python bindings (`drift-core-python`), defined in the [`drift-core`](https://github.com/Use-Tusk/drift-core) repository. This is controlled by environment flags and is designed to fail open.
8
+
9
+
At a high level:
10
+
11
+
- Python SDK logic remains the source of truth.
12
+
- Rust paths are opportunistic optimizations.
13
+
- If Rust is unavailable or fails at runtime, SDK behavior falls back to Python equivalents.
14
+
15
+
## Enablement
16
+
17
+
Set:
18
+
19
+
```bash
20
+
TUSK_USE_RUST_CORE=1
21
+
```
22
+
23
+
Truthy values are `1`, `true`, and `yes` (case-insensitive). Any other value is treated as disabled.
24
+
25
+
## Installation Requirements
26
+
27
+
Rust acceleration requires the `drift-core-python` package to be installed in the runtime environment.
28
+
29
+
Notes:
30
+
31
+
- The SDK does not auto-install this package at runtime.
32
+
- If the package is missing or cannot be imported on a machine, the SDK continues on Python code paths.
33
+
34
+
You can install the SDK with Rust bindings via extras:
35
+
36
+
```bash
37
+
pip install "tusk-drift-python-sdk[rust]"
38
+
```
39
+
40
+
## Wheel Platform Coverage
41
+
42
+
Based on the current `drift-core` publish workflow, prebuilt wheels are built for:
- Other uncommon Python/platform combinations not covered by release artifacts
55
+
56
+
If no wheel matches the environment, `pip` may attempt a source build of `drift-core-python`, which typically requires a Rust toolchain and native build prerequisites.
57
+
58
+
## Fallback Behavior
59
+
60
+
The bridge module is fail-open:
61
+
62
+
- Rust calls are guarded.
63
+
- On import failures or call exceptions, the corresponding helper returns `None`.
64
+
- Calling code then uses the existing Python implementation.
65
+
66
+
This means users do not need Rust installed to run the SDK when Rust acceleration is disabled or unavailable.
67
+
68
+
## Optional Performance Flag
69
+
70
+
```bash
71
+
TUSK_SKIP_PROTO_VALIDATION=1
72
+
```
73
+
74
+
This skips expensive protobuf validation checks in hot paths.
75
+
76
+
Use with care:
77
+
78
+
- Recommended only when parity/smoke tests are healthy.
79
+
- Keep it off in environments where strict serialization verification is preferred.
80
+
81
+
## Practical Guidance
82
+
83
+
- Default production-safe posture: leave Rust disabled unless you have tested your deployment matrix.
84
+
- Performance posture: enable Rust + benchmark on your workloads before broad rollout.
85
+
- Reliability posture: keep parity tests and smoke tests in CI to detect drift between Python and Rust paths.
0 commit comments