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.

PyPI Docs Python codecov

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

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.8.2.tar.gz (440.4 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.8.2-cp310-abi3-win_amd64.whl (6.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

spikard-0.8.2-cp310-abi3-manylinux_2_34_x86_64.whl (6.0 MB view details)

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

spikard-0.8.2-cp310-abi3-macosx_14_0_arm64.whl (5.5 MB view details)

Uploaded CPython 3.10+macOS 14.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spikard-0.8.2.tar.gz
Algorithm Hash digest
SHA256 f2c203be4c02f9d90ce6585eb228e1c676cee346fbb8f88a7a3ac554e64203e2
MD5 5769db8c75ecfb2c02816e344e5df559
BLAKE2b-256 8ccfcb6a1632247e738c1bc4ecc990ce05bd2974b959de17f5a6aca9bff7ba4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for spikard-0.8.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.8.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: spikard-0.8.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.8.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e0858050a0e3c24255967057845851e8deb8203627415a2b418497b9d7dc6dda
MD5 d5b3f6cd0711980df525c2fc963007f9
BLAKE2b-256 fbbc6d1da4c43771c2ab9ccce2f66775340c4ce2d6b6b3d198c72cd5e538b76b

See more details on using hashes here.

Provenance

The following attestation bundles were made for spikard-0.8.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.8.2-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for spikard-0.8.2-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 11659e462ffe1816c66eda77349403bc22697f17e18aadf846897f01467cce28
MD5 0396aa0c9a06596ef5d543ab2d19061b
BLAKE2b-256 603fc9dfc1feab911af460b6cabd0707e990abc6d8180b3b1d75bfcb868a4620

See more details on using hashes here.

Provenance

The following attestation bundles were made for spikard-0.8.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.8.2-cp310-abi3-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for spikard-0.8.2-cp310-abi3-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d52dc6e640c5f073d0c2a7c860ecd23e5907e1e5449cc9fed22996c76738b0bb
MD5 eadeb88ac257ab6f82b60171a47208b1
BLAKE2b-256 6b12142fc881d6ed81cf3263c90d4037920e3e2574795b2347165ef0bbf428c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for spikard-0.8.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