Skip to main content

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.

Documentation Crates.io PyPI npm Gem Packagist License

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
# 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")
def chat_endpoint():
    async def handler(message: dict) -> dict | None:
        return {"echo": message}
    return handler

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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spikard-0.10.2.tar.gz (537.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

spikard-0.10.2-cp310-abi3-win_amd64.whl (6.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

spikard-0.10.2-cp310-abi3-manylinux_2_34_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ x86-64

spikard-0.10.2-cp310-abi3-macosx_14_0_arm64.whl (5.4 MB view details)

Uploaded CPython 3.10+macOS 14.0+ ARM64

File details

Details for the file spikard-0.10.2.tar.gz.

File metadata

  • Download URL: spikard-0.10.2.tar.gz
  • Upload date:
  • Size: 537.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spikard-0.10.2.tar.gz
Algorithm Hash digest
SHA256 b69abca14062ec4395b8315a7ce7637a195b85fb497b2d6b957744f918e220b7
MD5 3f777a7966bbc538b0f62e35c6008405
BLAKE2b-256 7d77be0f467746190b231665e9e79a1f65de7700132087379349b3b1e416b850

See more details on using hashes here.

Provenance

The following attestation bundles were made for spikard-0.10.2.tar.gz:

Publisher: publish.yaml on Goldziher/spikard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spikard-0.10.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: spikard-0.10.2-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

Hashes for spikard-0.10.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8125849ce8f724ce9e3cb9837623ee56e96a8d4d298d1d877a57879025a9a314
MD5 2110f13ee346c89de9468bc5923fe1cf
BLAKE2b-256 11b8cec5fe900bd0c1e35087863ec523a644f34c7a487cb5305612e6de8f6100

See more details on using hashes here.

Provenance

The following attestation bundles were made for spikard-0.10.2-cp310-abi3-win_amd64.whl:

Publisher: publish.yaml on Goldziher/spikard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spikard-0.10.2-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for spikard-0.10.2-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ad3c1027bc985dd00671179ec0375c3f74fbfa2a95ac7b43c1988979d293700d
MD5 ed9b9bdbdab1e4cb7bf72d54ccdb148b
BLAKE2b-256 3e871f512b597addfb4e0213e9ad965f91d435407f7ebfe745c4e62cf39e8ebd

See more details on using hashes here.

Provenance

The following attestation bundles were made for spikard-0.10.2-cp310-abi3-manylinux_2_34_x86_64.whl:

Publisher: publish.yaml on Goldziher/spikard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spikard-0.10.2-cp310-abi3-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for spikard-0.10.2-cp310-abi3-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4edb2f8766749202c7c0da61fa156ec14cce9c5bc52abe7468336da60944de7a
MD5 8db82079ee1c555b05540582bde1ef2f
BLAKE2b-256 8aa43cba5577d91808e613ff6289e3a3f1cd2228032a374decbe5654dda91f97

See more details on using hashes here.

Provenance

The following attestation bundles were made for spikard-0.10.2-cp310-abi3-macosx_14_0_arm64.whl:

Publisher: publish.yaml on Goldziher/spikard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page