spvn

Ruff PyPI - Python Version Wheel


Rust ASGI bindings for python.

Features

  • Drop and go CLI for replacing transport layer handling
  • ASGI compliant protocols allowing direct import and use of python through rust
  • Fast

Sneak Peek

fastapi before uvicorn-fastapi-5000 fastapi after spvn-fastapi-5000

  • p99 @ 38x

Rationale & Goals

  • Relieve limits by python in networking applications

  • Safe python threadpooling

  • Uvicorn drops requests & stalls on IO > 7500 concurrent clients

  • Hypercorn drops requests & stalls on IO > 7500 concurrent clients

In both, we must horizontally scale to accomodate these limits in our systems. This is further accompanied by essentially a second layer of IO bound processes, which are evidently unable to maintain highly concurrent environments

What spvn does

Delegation of connection multiplex, stream, and IO processes into Rust, and autoinjection at runtime following standard ASGI protocol.

Performance

Tests performed using ali. See ali for methodology.

spvn @ 1000 reqs/s, 30s sustained

spvn-5000

  • app: fastapi
  • file: dotest.bit:app

spvn @ 5000 reqs/s

spvn-5000

  • app: custom
  • file: dotest.baz:app

spvn @ 10000 reqs/s

spvn-5000

  • app: custom
  • file: dotest.baz:app

uvicorn @ 1000 reqs/s

uvicorn-1000

  • app: custom
  • file: dotest.baz:app

uvicorn @ 5000 reqs/s (DDOS Success)

uvicorn-5000

  • app: custom
  • file: dotest.baz:app

hypercorn @ 1000 reqs/s

hypercorn-5000

  • app: custom
  • file: dotest.baz:app

hypercorn @ 5000 reqs/s (DDOS Success)

hypercorn-5000

  • app: custom
  • file: dotest.baz:app

Installation

spvn is offered as beta currently, keep in mind it has quirks and some features might be untested. for this reason, we dont recommend it for production use yet. if you find a bug, please submit an issue!

pypi

PyPI - Version

pip install spvn

crates

spvnCrates.io
spvn_callerCrates.io
spvn_lifespanCrates.io

Developing

Project Status

Roughly in order of priority

  • [✅] Integrate standard import semantics

  • [✅] PyCaller

    • [✅] (rust) Async safe integration
    • [✅] Abstract (py fn) async / sync handle
    • [✅] Caller pool [this will be revised, its too slow]
  • [✅] Standard asgi traits & structs

    • [✅] ASGIScope
      • [✅] (rust) Async safe integration
      • [✅] Conversion from tower::Body -> dict
    • [✅] ASGIVersion
    • [✅] ASGIMessage
      • [✅] Lifecycle Scope
      • [✅] HTTP Lifecycle Scope
      • [🚧] Websockets (msg integration)
  • [✅] App listener

  • [✅] App dispatcher

    • [✅] Async threadsafe
    • [🚧] Lifecycle activation for caller objects (unstable)
  • [🚧] App scheduler

    • [✅] Injectable awaitables (rust ptr -> python ptr)
    • [✅] Async threadsafe
    • [✅] Delayed py-fn call
    • [🚧] Scheduler into py
  • [🚧] Live reloader

  • [🚧] Websockets

Pre-requisites

Python >= 3.9

  1. Use virtualenv / venv
python3.10 -m (venv|virtualenv) env && \
        . ./env/bin/activate && \
        pip install maturin
  1. Test bindings by running
maturin develop

Rust >= 1.69.0

  • Build CLI
cargo build
  • Run CLI
cargo cli serve dotest.foo:app