Skip to main content

Cranker v3 connector for ASGI applications

Project description

asgi-cc

asgi-cc is a Python Cranker connector for ASGI applications. It connects an ASGI app to a Cranker router over WebSocket and forwards HTTP traffic through the Cranker v3 protocol without adding a loopback HTTP hop inside the service process.

Features

  • ASGI-native request and response bridging
  • Cranker v3 (cranker_3.0) protocol support
  • FastAPI-compatible integration
  • DNS-based router discovery
  • Optional suppression for asgi-cc and websockets logs
  • Runtime app attach and detach support

Requirements

  • Python 3.11+

Installation

pip install asgi-cc

Basic Usage

Create the connector with the application and let the app lifecycle manage the connector:

import os

from fastapi import FastAPI

from asgi_cc import CrankerConnector, CrankerConnectorConfig

app = FastAPI()


@app.get("/hello")
async def hello() -> dict[str, str]:
    return {"message": "hello through cranker"}


connector = CrankerConnector(
    app,
    CrankerConnectorConfig(
        router_urls=[os.environ.get("CRANKER_ROUTER_URL", "wss://localhost:12001")],
        route="*",
        verify_ssl=False,
        component_name="my-service",
    ),
)

Keep using app as the ASGI server entrypoint. The connector registers itself on the app startup and shutdown hooks.

Middleware Usage

import os

from fastapi import FastAPI

from asgi_cc import CrankerConnector, CrankerConnectorConfig

app = FastAPI()

app.add_middleware(
    CrankerConnector,
    config=CrankerConnectorConfig(
        router_urls=[os.environ.get("CRANKER_ROUTER_URL", "wss://localhost:12001")],
        route="*",
        verify_ssl=False,
        component_name="my-service",
    ),
)

Runtime App Management

connector = CrankerConnector(config=config)

await connector.attach(app)
await connector.detach()

If the connector is started without an attached app, incoming requests receive 503 Service Unavailable until an app is attached.

Router Discovery

config = CrankerConnectorConfig(
    router_urls=["wss://router.example.org"],
    route="*",
    router_lookup_by_dns=True,
    router_update_interval_seconds=60,
)

When enabled, asgi-cc resolves router hostnames to IP addresses, opens registrations for the currently resolved routers, and periodically reconciles router registrations as DNS changes.

Logging

Set disable_logging=True to suppress logs emitted by asgi-cc and the underlying websockets package:

config = CrankerConnectorConfig(
    router_urls=["wss://router.example.org"],
    route="*",
    disable_logging=True,
)

Project Links

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

asgi_cc-0.1.5.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

asgi_cc-0.1.5-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file asgi_cc-0.1.5.tar.gz.

File metadata

  • Download URL: asgi_cc-0.1.5.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asgi_cc-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3bd27de6cc58aed181201525cd19b4d98e129cee958947d6eb2c4642ff57dd57
MD5 e9693a0c963967c5da0bab7bed413d0a
BLAKE2b-256 17f123db30cae67cdcbd8381a6d441518acdbfce94a3d3e1bd7f328b95b92ec6

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgi_cc-0.1.5.tar.gz:

Publisher: release.yml on wenLiangcan/asgi-cc

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

File details

Details for the file asgi_cc-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: asgi_cc-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asgi_cc-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 898f6833b3c4b66db45711cc2adbdc3011698c919b3a81e67e3ff78ee4ed6f3c
MD5 d8dd21e611ea7563fc946744903c552c
BLAKE2b-256 b8b45fda735a6479ac188d72181e387a85db74dab1c5096997b98156a67cf0c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgi_cc-0.1.5-py3-none-any.whl:

Publisher: release.yml on wenLiangcan/asgi-cc

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