Skip to content

SuperInstance/api-gateway-1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

api-gateway-1 — Pure-Python API Gateway

Routing, middleware, rate limiting, and request transformation. Zero external dependencies beyond pytest.

What This Gives You

  • Router — pattern-based URL routing with parameter extraction
  • Middleware chain — composable request/response processing pipeline
  • Rate limiting — token bucket, sliding window, and fixed window algorithms
  • Request transformation — modify requests and responses with configurable rules
  • Pure Python — built with dataclasses and type hints, no framework dependency

Quick Start

pip install api-gateway
from api_gateway import Gateway, Router, Route, Middleware, RateLimiter

# Set up routing
router = Router()
router.add(Route(path="/v1/chat", handler=chat_handler))
router.add(Route(path="/v1/models", handler=models_handler))

# Add middleware
gateway = Gateway(router=router)
gateway.use(Middleware(rate_limit=RateLimiter(max_requests=100, window_seconds=60)))
gateway.use(Middleware(transform=RequestTransformer(add_header={"X-Fleet": "cocapn"})))

# Process a request
response = gateway.handle(request)

API Reference

Gateway(router, middleware=None)handle(request) → response

Routeradd(route), match(path) → Route

Route(path, handler, methods=None)

Middleware(chain) — Composable request/response processor

RateLimiter / TokenBucketLimiter / SlidingWindowLimiter / FixedWindowLimiter

RequestTransformer(rules)TransformRule(field, action, value)

How It Fits

The gateway backing cocapn-sdk and cocapn-py — the "one API key, any model" endpoint runs through this.

Testing

pip install pytest
pytest tests/

Installation

pip install api-gateway

Python 3.10+. MIT license.

Documentation

📚 OpenConstruct Docs

About

Unified API gateway — single entry point for all fleet vessel APIs

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%