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.
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 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(port=8000)
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
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
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
app.provide("db", Provide(create_pool, singleton=True))
@app.get("/data")
async def get_data(db): # Injected automatically
return {"data": await db.fetch("SELECT * FROM items")}
WebSockets:
from spikard import websocket
@websocket("/ws")
async def chat(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 Configuration Guide for all options.
Performance
Spikard is 2.8x faster than FastAPI on real-world workloads:
| Metric | Spikard | FastAPI |
|---|---|---|
| Throughput | 35,779 req/s | 12,776 req/s |
| Latency | 7.44ms | 7.90ms |
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 import TestClient
client = TestClient(app)
response = client.get("/users/123")
assert response.status_code == 200
See Testing Guide 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
Other Languages
- Rust: Crates.io
- TypeScript: npm (@spikard/node)
- Ruby: RubyGems
- PHP: Packagist
- WebAssembly: npm (@spikard/wasm)
License
MIT
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.7.3.tar.gz.
File metadata
- Download URL: spikard-0.7.3.tar.gz
- Upload date:
- Size: 411.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0aeb6ea88c221808b4053efbcafbe5fd5d29620889009ecc53ab70bb33ef228
|
|
| MD5 |
49c2b3f42283990f6f41cb573043bbeb
|
|
| BLAKE2b-256 |
05f0b7aba97eb2e20ab86bbf0a337919d410ecf50f1702f4708638d5288adb4f
|
Provenance
The following attestation bundles were made for spikard-0.7.3.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.7.3.tar.gz -
Subject digest:
a0aeb6ea88c221808b4053efbcafbe5fd5d29620889009ecc53ab70bb33ef228 - Sigstore transparency entry: 784009061
- Sigstore integration time:
-
Permalink:
Goldziher/spikard@ff9ed44fb470584e2a58b2bb4c133471da2ce323 -
Branch / Tag:
refs/tags/v0.7.3 - Owner: https://github.com/Goldziher
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@ff9ed44fb470584e2a58b2bb4c133471da2ce323 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spikard-0.7.3-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: spikard-0.7.3-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 6.2 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 |
f20b521eef8c891cadd3d78211a0ed178f0bf99afdbb0742880718c891f2f1c5
|
|
| MD5 |
3edc49b118fca4facd23251e7f0b196f
|
|
| BLAKE2b-256 |
d2f9b687d8b7e2ab26e15955cbe8cfffa2bcf713ffd4df19090717dbda1dfcf0
|
Provenance
The following attestation bundles were made for spikard-0.7.3-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.7.3-cp310-abi3-win_amd64.whl -
Subject digest:
f20b521eef8c891cadd3d78211a0ed178f0bf99afdbb0742880718c891f2f1c5 - Sigstore transparency entry: 784009107
- Sigstore integration time:
-
Permalink:
Goldziher/spikard@ff9ed44fb470584e2a58b2bb4c133471da2ce323 -
Branch / Tag:
refs/tags/v0.7.3 - Owner: https://github.com/Goldziher
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@ff9ed44fb470584e2a58b2bb4c133471da2ce323 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spikard-0.7.3-cp310-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: spikard-0.7.3-cp310-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.0 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 |
73df82c3407510c9ea6c0df150a244c20f97a95ea9c86f8b93edfe24bf4ed55c
|
|
| MD5 |
6f35c433946bd5a25d04897d03a379a7
|
|
| BLAKE2b-256 |
37f384bab75f5b2e61d29d22f7f99db0fc0b3a1f3c9193c3d0c89a007f4ad772
|
Provenance
The following attestation bundles were made for spikard-0.7.3-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.7.3-cp310-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
73df82c3407510c9ea6c0df150a244c20f97a95ea9c86f8b93edfe24bf4ed55c - Sigstore transparency entry: 784009154
- Sigstore integration time:
-
Permalink:
Goldziher/spikard@ff9ed44fb470584e2a58b2bb4c133471da2ce323 -
Branch / Tag:
refs/tags/v0.7.3 - Owner: https://github.com/Goldziher
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@ff9ed44fb470584e2a58b2bb4c133471da2ce323 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spikard-0.7.3-cp310-abi3-macosx_14_0_arm64.whl.
File metadata
- Download URL: spikard-0.7.3-cp310-abi3-macosx_14_0_arm64.whl
- Upload date:
- Size: 5.5 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 |
8b06da0796369c5a9b86704928740c01df38a6b8df2e327b92da98a302ca1e26
|
|
| MD5 |
8a5d9eb4e59a5d05227a67ebac10528d
|
|
| BLAKE2b-256 |
bca4f7fab42d993660def32e763fc11f926cb505a974de1cbc01c8f8c3aa41c5
|
Provenance
The following attestation bundles were made for spikard-0.7.3-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.7.3-cp310-abi3-macosx_14_0_arm64.whl -
Subject digest:
8b06da0796369c5a9b86704928740c01df38a6b8df2e327b92da98a302ca1e26 - Sigstore transparency entry: 784009201
- Sigstore integration time:
-
Permalink:
Goldziher/spikard@ff9ed44fb470584e2a58b2bb4c133471da2ce323 -
Branch / Tag:
refs/tags/v0.7.3 - Owner: https://github.com/Goldziher
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@ff9ed44fb470584e2a58b2bb4c133471da2ce323 -
Trigger Event:
release
-
Statement type: