Skip to main content

ulfblk-gateway

API Gateway con rate limiting (Redis/in-memory), reverse proxy via httpx, y circuit breaker para proteger upstreams.

Instalacion

uv add ulfblk-gateway

Rate Limiting

from ulfblk_gateway.rate_limiter import (
    InMemoryBackend,
    RateLimiterMiddleware,
    RateLimiterSettings,
)

settings = RateLimiterSettings(
    requests=100,          # max por ventana
    window_seconds=60,
    exclude_paths=["/health"],
)
backend = InMemoryBackend()

app.add_middleware(RateLimiterMiddleware, settings=settings, backend=backend)

Con Redis (soft dependency via ulfblk-redis):

from ulfblk_gateway.rate_limiter import RedisBackend, RateLimiterMiddleware, RateLimiterSettings
from ulfblk_redis import RedisManager

redis = RedisManager()
await redis.connect()

backend = RedisBackend(redis)
app.add_middleware(
    RateLimiterMiddleware,
    settings=RateLimiterSettings(requests=100, window_seconds=60),
    backend=backend,
)

Reverse Proxy

from ulfblk_gateway.proxy import ProxyHandler, ProxyMiddleware, ProxyRoute, ProxySettings

settings = ProxySettings(
    routes=[
        ProxyRoute(path_prefix="/api/users", upstream_url="http://user-service:8001"),
        ProxyRoute(path_prefix="/api/orders", upstream_url="http://order-service:8002"),
    ]
)

handler = ProxyHandler(settings)
await handler.start()

app.add_middleware(ProxyMiddleware, handler=handler)

Circuit Breaker

from ulfblk_gateway.circuit_breaker import CircuitBreaker, CircuitBreakerSettings

cb = CircuitBreaker("user-service", CircuitBreakerSettings(
    failure_threshold=5,
    recovery_timeout=30.0,
    success_threshold=2,
))

# Integrado con proxy middleware
app.add_middleware(
    ProxyMiddleware,
    handler=handler,
    circuit_breakers={"http://user-service:8001": cb},
)

Health Check

from ulfblk_gateway.health import gateway_health_check

status = await gateway_health_check(handler)
# {"gateway": True, "upstream:http://user-service:8001": True}

Dependencias

  • ulfblk-core (obligatorio)
  • httpx>=0.27 (obligatorio)
  • ulfblk-redis (opcional, para RedisBackend)

License

MIT

Metadata

Release files for ulfblk-gateway 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ulfblk-gateway 0.1.0
File Size Uploaded
ulfblk_gateway-0.1.0.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ulfblk-gateway 0.1.0
File Interpreter ABI Platform
ulfblk_gateway-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / ulfblk_gateway-0.1.0.tar.gz

Download URL ulfblk_gateway-0.1.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a492c909d2548251cff743994ebd136f474a31f8b971606771248c5d7155ae7f
BLAKE2b-256 checksum
How to use checksums
dc64a294a81bcf3231b28e51c9c149ce82921ad789711239f5f77f893399997c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ulfblk_gateway-0.1.0-py3-none-any.whl

Download URL ulfblk_gateway-0.1.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a29fd105a104641baa788147eadbd4f0d0400e17d8c3dfe3cc7bf704a059628c
BLAKE2b-256 checksum
How to use checksums
9b134c5396de78f70270e6714533a29917b64ef184705ba956b8a436b8cdcc94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page