High-performance Python web framework with a Rust core. Build REST APIs, WebSockets, and SSE services with FastAPI/Litestar-style decorators backed by Axum and Tower-HTTP. 2.8x faster than FastAPI.
Project description
Spikard Python
High-performance Python web framework backed by a Rust core. Build REST APIs, WebSockets, and SSE services with FastAPI/Litestar-style decorators powered by Tokio, Hyper, and Tower middleware.
Features
- Multiple route styles: FastAPI-style (
@app.get()) or Litestar-style (@get()) - Automatic validation: msgspec (default), Pydantic v2, dataclasses, TypedDict, NamedTuple
- Request/response streaming: WebSockets, Server-Sent Events, multipart uploads
- Middleware stack: Compression, rate limiting, request IDs, authentication, CORS
- Async-first: Full async/await with
pyo3_async_runtimes - OpenAPI generation: Automatic type introspection and documentation
- Dependency injection: Configurable container with singleton and factory support
Installation
pip install spikard
Pre-built wheels available for macOS, Linux, Windows. Building from source requires Rust 1.75+.
Development:
cd packages/python && uv sync
Requirements: Python 3.10+
Quick Start
from spikard import Spikard
from spikard.config import ServerConfig
from msgspec import Struct
class User(Struct):
id: int
name: str
email: str
app = Spikard()
@app.get("/users/{user_id}")
async def get_user(user_id: int) -> User:
return User(id=user_id, name="Alice", email="alice@example.com")
@app.post("/users")
async def create_user(user: User) -> User:
# Automatic validation via msgspec
return user
if __name__ == "__main__":
app.run(config=ServerConfig(port=8000))
Core Concepts
Route Decorators:
from spikard import Spikard, get, post
app = Spikard()
@app.get("/users/{user_id}")
async def get_user(user_id: int):
return {"id": user_id}
@post("/users") # Standalone decorator style
async def create_user(user: User):
return user
# Note: standalone decorators require app.include_router(get_default_router()) before app.run()
Validation with msgspec (recommended):
from msgspec import Struct
class User(Struct):
name: str
email: str
@app.post("/users")
async def create_user(user: User):
return user # Automatic validation
Dependency Injection:
from spikard.di import Provide
class DatabasePool:
async def fetch(self, sql: str) -> list: ...
def create_pool() -> DatabasePool:
return DatabasePool()
app.provide(DatabasePool, Provide(create_pool, singleton=True))
@app.get("/data")
async def get_data(pool: DatabasePool) -> dict:
return {"data": await pool.fetch("SELECT * FROM items")}
WebSockets:
from spikard import websocket
@app.websocket("/ws")
async def chat_endpoint(message: dict) -> dict | None:
return {"echo": message}
Server-Sent Events:
from spikard import sse
@sse("/events")
async def stream():
for i in range(10):
yield {"count": i}
Lifecycle Hooks:
@app.pre_validation
async def check_auth(request):
if not request.headers.get("authorization"):
return Response({"error": "Unauthorized"}, 401)
return request
Configuration
from spikard import Spikard, ServerConfig, CompressionConfig, RateLimitConfig, JwtConfig
config = ServerConfig(
host="0.0.0.0",
port=8080,
workers=4,
compression=CompressionConfig(gzip=True, brotli=True),
rate_limit=RateLimitConfig(per_second=100, burst=200),
jwt=JwtConfig(secret="key", algorithm="HS256")
)
app = Spikard(config=config)
See the documentation for all options.
Performance
Benchmarked across 34 workloads at 100 concurrency (methodology):
| Framework | Avg RPS | P50 (ms) | P99 (ms) |
|---|---|---|---|
| spikard | 12,623 | 5.55 | 38.39 |
| litestar | 8,032 | 14.62 | 19.18 |
| fastapi | 6,418 | 16.43 | 21.72 |
| robyn | 6,012 | 16.85 | 24.18 |
Spikard is 1.6x faster than Litestar (throughput-based; see full results for latency breakdown), 2.0x faster than FastAPI, and 2.1x faster than Robyn (also Rust-backed).
Key optimizations:
- Zero-copy PyO3 type conversion (no JSON round-trips)
- Rust-powered HTTP server (Tokio + Hyper)
- GIL-friendly async design with
pyo3_async_runtimes
Testing
from spikard.testing import TestClient
async def test_users():
async with TestClient(app) as client:
response = await client.get("/users/123")
assert response.status_code == 200
assert response.json()["id"] == 123
TestClient uses in-process Rust testing for speed. LiveTestClient starts a real subprocess server for WebSocket/SSE tests.
See the main documentation for WebSocket and SSE testing.
Examples
Runnable examples with dependency injection and database integration:
See examples/README.md for all languages and code generation.
Documentation
Full documentation at spikard.dev. See also CONTRIBUTING.md.
Other Languages
- Rust: Crates.io
- Python: PyPI
- TypeScript: npm (@spikard/node)
- Ruby: RubyGems
- PHP: Packagist
- Elixir: Hex.pm
License
MIT - See LICENSE for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spikard-0.13.0.tar.gz.
File metadata
- Download URL: spikard-0.13.0.tar.gz
- Upload date:
- Size: 552.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4ac0f2301336a6f28037bddab7902b5946087946e49686dd89c8c719f48b4ad
|
|
| MD5 |
0992b13595081dc250fcecd548974057
|
|
| BLAKE2b-256 |
43c8b50c8f6c0e3b752e5b7342bbc994e3361802d1c6f3d9713d821d3ea330e8
|
Provenance
The following attestation bundles were made for spikard-0.13.0.tar.gz:
Publisher:
publish.yaml on Goldziher/spikard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spikard-0.13.0.tar.gz -
Subject digest:
c4ac0f2301336a6f28037bddab7902b5946087946e49686dd89c8c719f48b4ad - Sigstore transparency entry: 1138135837
- Sigstore integration time:
-
Permalink:
Goldziher/spikard@abb1dcce798ba6d749195fc11f36eb1294634ec9 -
Branch / Tag:
refs/tags/v0.13.0 - Owner: https://github.com/Goldziher
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@abb1dcce798ba6d749195fc11f36eb1294634ec9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spikard-0.13.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: spikard-0.13.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6660a913c07ae5d7710c1d227afd9f83929fc80008baec14079ffd20788643ff
|
|
| MD5 |
af5faff10423a0453bf85cbe73ba5ddb
|
|
| BLAKE2b-256 |
84487bc151b9be70fd2a936702451da7b46b269afcd9083929e82facb397b691
|
Provenance
The following attestation bundles were made for spikard-0.13.0-cp310-abi3-win_amd64.whl:
Publisher:
publish.yaml on Goldziher/spikard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spikard-0.13.0-cp310-abi3-win_amd64.whl -
Subject digest:
6660a913c07ae5d7710c1d227afd9f83929fc80008baec14079ffd20788643ff - Sigstore transparency entry: 1138136025
- Sigstore integration time:
-
Permalink:
Goldziher/spikard@abb1dcce798ba6d749195fc11f36eb1294634ec9 -
Branch / Tag:
refs/tags/v0.13.0 - Owner: https://github.com/Goldziher
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@abb1dcce798ba6d749195fc11f36eb1294634ec9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spikard-0.13.0-cp310-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: spikard-0.13.0-cp310-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.10+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef44e4de2aeb56cddd146a5f1af33d7f0fd6d2d5e71661fb5f0c5697f106c179
|
|
| MD5 |
15d0a685b69d17de30bd57427d6cf51d
|
|
| BLAKE2b-256 |
1bc5850b8c306c7d9be98f4da39e9a556bc6a08a5a25e670ba56f57e9ba32661
|
Provenance
The following attestation bundles were made for spikard-0.13.0-cp310-abi3-manylinux_2_34_x86_64.whl:
Publisher:
publish.yaml on Goldziher/spikard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spikard-0.13.0-cp310-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
ef44e4de2aeb56cddd146a5f1af33d7f0fd6d2d5e71661fb5f0c5697f106c179 - Sigstore transparency entry: 1138136132
- Sigstore integration time:
-
Permalink:
Goldziher/spikard@abb1dcce798ba6d749195fc11f36eb1294634ec9 -
Branch / Tag:
refs/tags/v0.13.0 - Owner: https://github.com/Goldziher
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@abb1dcce798ba6d749195fc11f36eb1294634ec9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spikard-0.13.0-cp310-abi3-macosx_14_0_arm64.whl.
File metadata
- Download URL: spikard-0.13.0-cp310-abi3-macosx_14_0_arm64.whl
- Upload date:
- Size: 5.7 MB
- Tags: CPython 3.10+, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8297c6d0cc24e3004046e7cc59861fa6e3088f2f8369524df8437f05873dcf40
|
|
| MD5 |
15758dc78d1447a169bc3c22875a7a94
|
|
| BLAKE2b-256 |
6f0ee9c801783587b2f97943abc9104bfbbde97031abe81a723552f3d90822a7
|
Provenance
The following attestation bundles were made for spikard-0.13.0-cp310-abi3-macosx_14_0_arm64.whl:
Publisher:
publish.yaml on Goldziher/spikard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spikard-0.13.0-cp310-abi3-macosx_14_0_arm64.whl -
Subject digest:
8297c6d0cc24e3004046e7cc59861fa6e3088f2f8369524df8437f05873dcf40 - Sigstore transparency entry: 1138135936
- Sigstore integration time:
-
Permalink:
Goldziher/spikard@abb1dcce798ba6d749195fc11f36eb1294634ec9 -
Branch / Tag:
refs/tags/v0.13.0 - Owner: https://github.com/Goldziher
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@abb1dcce798ba6d749195fc11f36eb1294634ec9 -
Trigger Event:
release
-
Statement type: