Project

spikard

0.02
A long-lived project that still receives updates
Spikard is a Rust-centric multi-language HTTP toolkit providing a high-performance core library and language bindings (Python, Node.js, Ruby, PHP, WebAssembly) to build and validate typed web services. The Ruby binding uses Magnus for zero-overhead FFI, providing Sinatra-style routing, full async/await support, WebSockets, Server-Sent Events, request validation with JSON Schema and dry-schema, lifecycle hooks, dependency injection, and comprehensive middleware stack (compression, rate limiting, authentication). Features: - Zero-copy Rust-to-Ruby serialization via Magnus - Async-first with Tokio and Axum backing - Type-safe RBS type definitions for Steep - Tower-HTTP middleware stack - Lifecycle hooks (onRequest, preValidation, preHandler, onResponse, onError) - Built-in WebSocket and SSE support - Request validation with JSON Schema
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Spikard

A Rust-centric multi-language toolkit for building and validating typed web services. Generate type-safe API handlers from OpenAPI, GraphQL, gRPC/Protobuf, AsyncAPI, or JSON-RPC specifications and deploy to Python, TypeScript, Ruby, PHP, or WebAssembly.

Rust Python TypeScript Ruby PHP

Features

  • Multi-Language Code Generation: Generate type-safe handlers from OpenAPI 3.0.x, GraphQL SDL, gRPC/Protobuf, AsyncAPI 2.x, or OpenRPC 1.x specifications
  • Project Scaffolding: spikard init bootstraps production-ready projects with language-specific tooling
  • Automatic Quality Validation: Syntax, type checking, and linting automatically applied to generated code
  • Zero-Copy Bindings: Performance-optimized FFI layers (PyO3, napi-rs, magnus, ext-php-rs, wasm-bindgen)
  • Tower-HTTP Runtime: Complete HTTP/gRPC server with compression, rate limiting, authentication, and CORS
  • Fixture-Driven Testing: Comprehensive test coverage with JSON-based fixtures

Supported Languages

Language Version Package Manager
Python 3.10+ pip / uv
TypeScript 5.x npm / pnpm / yarn
Ruby 3.2+ bundler
PHP 8.2+ Composer
Rust 2024 cargo
WebAssembly Latest wasm-pack

Quick Start

Installation

cargo install spikard-cli

Create a New Project

spikard init --name my_api --language python
cd my_api
uv sync
python -m my_api.app

Generate Handlers from Specification

# From OpenAPI
spikard codegen --spec openapi.json --language python --output ./generated

# From GraphQL schema
spikard codegen --spec schema.graphql --language typescript --output ./src/generated

# From Protobuf schema
spikard codegen --spec user_service.proto --language python --output ./generated

See Init Command Guide for detailed options.

Code Examples

Generated handler patterns vary by language. See examples/ for complete runnable projects.

Python:

from spikard import Handler, Request, Response

@Handler("/users/{id}")
async def get_user(request: Request) -> Response:
    user_id = request.path_params["id"]
    return Response({"id": user_id, "name": "Alice"})

TypeScript:

import { Handler, Request, Response } from "spikard";

export const getUser: Handler = async (request) => {
    const user = { id: request.params.id, name: "Alice" };
    return new Response(user);
};

Ruby:

class GetUserHandler
  def call(request)
    { id: request.path_params["id"], name: "Alice" }
  end
end

PHP:

class Handlers {
    public function getUser(Request $request): Response {
        return new Response(["id" => $request->pathParams["id"], "name" => "Alice"]);
    }
}

Code Generation Support

Spikard generates type-safe handlers from multiple API specifications:

Format Support Languages
OpenAPI 3.0.x Python, TypeScript, Ruby, PHP
GraphQL SDL Python, TypeScript, Ruby, PHP, Rust
gRPC/Protobuf Python, TypeScript, Ruby, PHP, Rust
AsyncAPI 2.x Python, TypeScript, Ruby, PHP
OpenRPC 1.x Python, TypeScript, Ruby, PHP

All generated code is automatically validated for syntax, types, and style before output.

Development

Install dependencies and build all language bindings:

task setup      # Install all dependencies
task build      # Build all language bindings
task test       # Run all tests
task lint       # Check code quality
task format     # Apply formatting

Language-specific commands:

task build:python    # Build Python bindings
task build:node      # Build Node.js bindings
task build:ruby      # Build Ruby bindings
task build:php       # Build PHP bindings
task test:rust       # Run Rust tests
task test:python     # Run Python tests
task test:js         # Run TypeScript tests

Documentation

Architecture Highlights

Thin Binding Pattern: All language bindings delegate heavy lifting to the Rust core. Bindings handle language-specific type conversions only; no business logic duplication ensures consistency across platforms.

Zero-Copy Serialization: Direct PyO3 type construction eliminates JSON round-trips, providing 30-40% performance improvement in Python bindings.

Quality-First Generation: Automatic syntax, type, and style validation applied to all generated code. 95%+ test coverage on core generators.

Contributing

See CONTRIBUTING.md for guidelines. Code quality standards:

  • Rust: clippy -D warnings, 95%+ coverage
  • Python: mypy --strict, 95%+ coverage
  • TypeScript: Strict mode, 80%+ coverage
  • Ruby/PHP: 80%+ coverage

Pull request workflow: fork, create feature branch, run task lint and task test, update CHANGELOG.md, submit PR.

License

Licensed under the MIT License. See LICENSE file for details.