Skip to main content

rust asgi bindings for spic & span apis

Project description

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 docs/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

spvn Crates.io
spvn_caller Crates.io
spvn_lifespan Crates.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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spvn-0.1.1b1.tar.gz (38.5 kB view hashes)

Uploaded Source

Built Distributions

spvn-0.1.1b1-cp311-none-win_amd64.whl (1.9 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

spvn-0.1.1b1-cp310-none-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

spvn-0.1.1b1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (3.5 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

spvn-0.1.1b1-cp310-cp310-macosx_10_7_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

spvn-0.1.1b1-cp39-none-win_amd64.whl (1.9 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

spvn-0.1.1b1-cp38-none-win_amd64.whl (1.9 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page