Dreaming Electric Sheep
"The cloud has a head and two pairs of legs. It resembles a sheep."
Dreaming Electric Sheep is an ultra-high-performance, bare-metal asynchronous ASGI web framework for modern CPython (3.13–3.14+). Born as an aggressively optimized evolution of BlackSheep, it discards legacy runtime compromises (such as PyPy compatibility shims) to squeeze maximum throughput, microsecond-level latency, and direct C/C++/CUDA interoperability from standard CPython.
🔮 Key Highlights & Low-Level Architectural Features
1. 👾 PEP 590 Vectorcall Direct C-API Dispatch
All handler, middleware, and route dispatching bypasses Python *args tuple and **kwargs dict allocations. Handlers are invoked using PyObject_Vectorcall passing contiguous pointer arrays directly in CPU registers.
2. ⚓ Pure cdef class Extension Types (Zero __dict__ Overhead)
Request, Response, RouteMatch, Header, and Scope are pure Cython extension classes. All fields reside at fixed C-level struct offsets (pointer offset), eliminating dictionary lookups in the hot path.
3. 🌊 C-Level Object Freelists & Fast Pools
Request and Response instances are managed through dedicated C freelists (acquire_request, release_request, acquire_response, release_response), recycling objects across HTTP lifecycles and reducing Python heap pressure to near zero.
4. 🚄 SIMD Vectorization (AVX2 / SSE4.2 / ARM NEON / SWAR)
Custom C SIMD kernels accelerate:
- CRLF and header boundary scanning (
\r\n\r\n). - URL path separator tokenization (
/). - ASCII header validation with fallback SWAR (SIMD Within A Register).
5. 🧊 In-Memory Request Scratchpad Arenas
Per-request linear arenas (scratchpad.h/.c) allow $\mathcal{O}(1)$ allocation and instant bulk resets without invoking malloc() or free() during request lifecycle processing.
6. 💎 Zero-Copy ASGI Ingestion
Direct bytes-like memoryview and buffer passing from server transport layers (Granian, Uvicorn) directly into msgspec decoders without intermediate string copies or heap duplications.
7. 🔋 Pre-Compiled Type Decoders & Fast DI Bindings
Endpoint payload decoders (msgspec.json.Decoder(type=...)) and controller activation paths are compiled ahead-of-time during application startup, eradicating runtime reflection.
🐍 CPython & C / C++ / CUDA Native Interoperability
[!IMPORTANT] Why CPython exclusively? Dreaming Electric Sheep purposefully removes PyPy and legacy Python support to target modern CPython C-APIs (3.13, 3.14+). If your workloads utilize:
- C / C++ Native Extensions (e.g., custom Cython, pybind11, nanobind)
- CUDA / TensorRT / PyTorch / ONNX Runtime for high-throughput AI/ML serving
- SIMD hardware intrinsics (AVX2, AVX-512, NEON)
CPython provides the tightest possible low-overhead binding without JIT tracing overhead or foreign function interface (FFI) penalties.
⭐ Installation
pip install dreaming-electric-sheep
For maximum throughput and SIMD speed, install with httptools and uvloop:
pip install dreaming-electric-sheep httptools uvloop uvicorn granian msgspec
⚡ Quick Start & msgspec Integration
Dreaming Electric Sheep provides first-class, zero-overhead support for msgspec.Struct, dataclasses, and pydantic models with startup-cached pre-compiled decoders.
from dreaming_electric_sheep import Application, get, post
from msgspec import Struct
# Fast, schema-validated msgspec Struct
class CreateItemInput(Struct):
name: str
price: float
tags: list[str] = []
app = Application()
@get("/hello")
async def hello():
return {"message": "Do electric sheep dream of high throughput?"}
@post("/api/items")
async def create_item(data: CreateItemInput):
# Bound automatically with zero-copy buffer ingestion
return {"status": "created", "item": data}
📙 OpenAPI 3.0, Swagger UI, Scalar & ReDoc
Dreaming Electric Sheep automatically generates OpenAPI 3.0 documentation from type annotations (msgspec.Struct, dataclasses, Pydantic, Python typing) and docstrings. It includes built-in support for Swagger UI, Scalar, and ReDoc.
from dreaming_electric_sheep import Application, get, post
from dreaming_electric_sheep.server.openapi.v3 import OpenAPIHandler
from dreaming_electric_sheep.server.openapi.ui import (
SwaggerUIProvider,
ScalarUIProvider,
ReDocUIProvider,
)
from openapidocs.v3 import Info
from msgspec import Struct
app = Application()
# Configure OpenAPI with interactive documentation UIs
docs = OpenAPIHandler(
info=Info(title="Dreaming Electric Sheep API", version="1.0.0"),
ui_providers=[
SwaggerUIProvider("/docs"), # Interactive Swagger UI at /docs
ScalarUIProvider("/scalar"), # Modern Scalar UI at /scalar
ReDocUIProvider("/redoc"), # ReDoc at /redoc
],
)
docs.bind_app(app)
class Sheep(Struct):
id: int
name: str
voltage: float
@get("/api/sheep/:id")
async def get_sheep(id: int) -> Sheep:
"""
Retrieve an Electric Sheep by ID.
"""
return Sheep(id=id, name="Cloud Sheep", voltage=220.0)
Now navigate in your browser:
- Swagger UI:
http://localhost:8000/docs - Scalar UI:
http://localhost:8000/scalar - ReDoc:
http://localhost:8000/redoc - Raw OpenAPI JSON Spec:
http://localhost:8000/openapi.json
🔥 High-Speed Serialization: JSON & MessagePack
Take full advantage of pre-compiled type decoders and multiple wire formats:
from dreaming_electric_sheep import Application, FromJSON, FromMsgPack, FromQuery, post
from msgspec import Struct
class SensorPayload(Struct):
device_id: str
readings: list[float]
app = Application()
# JSON payload with precompiled type decoder
@post("/api/sensors/json")
async def ingest_json(data: FromJSON[SensorPayload]):
return {"received_readings": len(data.value.readings)}
# Binary MessagePack payload (ultra-fast binary format)
@post("/api/sensors/msgpack")
async def ingest_msgpack(data: FromMsgPack[SensorPayload]):
return {"received_readings": len(data.value.readings)}
🚀 Running the Application (CLI & ASGI Servers)
Dreaming Electric Sheep is a standard ASGI 3 application compatible with all ASGI servers.
1. Granian (Recommended for Extreme Throughput)
Granian is a high-performance Rust-based HTTP server.
# Production: Multi-threaded & Multi-worker
granian --interface asgi app:app --port 8000 --workers 4 --threads 2
# Development: Auto-reload
granian --interface asgi app:app --port 8000 --reload
2. Uvicorn (with uvloop & httptools)
Uvicorn provides a battle-tested Python/C networking stack.
# Production: uvloop + httptools
uvicorn app:app --port 8000 --loop uvloop --http httptools --workers 4
# Development: Auto-reload
uvicorn app:app --port 8000 --reload
🎯 Controllers & Dependency Injection
Dreaming Electric Sheep includes built-in dependency injection with pre-bound fast dispatching:
from dreaming_electric_sheep import Application
from dreaming_electric_sheep.server.controllers import Controller, get, post
class DatabaseService:
def get_stats(self) -> dict:
return {"active_connections": 42}
app = Application()
app.services.add_singleton(DatabaseService)
class StatusController(Controller):
@get("/api/status")
def get_status(self, db: DatabaseService):
return {"status": "ok", "db": db.get_stats()}
app.controllers.register(StatusController)
made with by EduLoboM
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dreaming_electric_sheep-1.0.0.tar.gz.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0.tar.gz
- Upload date:
- Size: 1.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9a362bc53bc520c770ecf258c3ebc26f16979c1aeb33aca88d5115872f91d87
|
|
| MD5 |
4c95ee49604739df8e7283b09f143a7b
|
|
| BLAKE2b-256 |
b4b164acd1a7412b2e35881347ca9dd72e4db853e7c3942d6ada70521d0cd382
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp314-cp314-win_arm64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp314-cp314-win_arm64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.14, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
724d65d70dbd9dc804076b08e609b00e81b6b9eef0321bdbb6dd8314ec5b499b
|
|
| MD5 |
1968bacbf8dfc7b66796f3e9bbfd9089
|
|
| BLAKE2b-256 |
67cb3b4e41e16a0738cdb3428bde96d422eddf76af8d59c7404fb5b68807cce5
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8945fda6c8c507bcfe18c2a7d7284930df9f8385cb9ec001f8803ecb99e31b7b
|
|
| MD5 |
621877c03ffce30e5608917da07b9e6a
|
|
| BLAKE2b-256 |
3684ea8c25e506043ea389abdcca662a8d2ec64262b8653a9f1d7e4d128cd011
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp314-cp314-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp314-cp314-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 6.7 MB
- Tags: CPython 3.14, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ba1f2205daa76df2146faf0f6dd65deba551915490231e00675e05a857ff8fd
|
|
| MD5 |
c4b8986083f1ed4e201d7d6aa95131de
|
|
| BLAKE2b-256 |
e008fb42f1146fc850b1a132d920c9adb497465bff767164200c50cf88b4fbdd
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp314-cp314-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp314-cp314-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 6.7 MB
- Tags: CPython 3.14, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcd27ecf045679d1ae7aa092ffc12d19b1e232f18bea9961be3104b9783decff
|
|
| MD5 |
5084ec8a5a3c8eb4bd17cd27bfb71fb3
|
|
| BLAKE2b-256 |
3ee39a59496e2157e2d15082f1c8f741ed787632485e7af1455a45e444f19975
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 6.9 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7152196b9d79e2ad940072ab7c021167473aeba0dc00bc721e495a919518ddc0
|
|
| MD5 |
6731057b0c4bb4beb1a553db3ff327bd
|
|
| BLAKE2b-256 |
7764389d74e68ab72f8d900310c8ef7da1297df41869bf3c5fe3b1b6b6c35abb
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 6.9 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffbd77cdf0eb1ab38e6dc341ecb5a3f475028cb80bd65e5c2306c0bdd716e29e
|
|
| MD5 |
58afcd22e1061eb72131e9fac7bf9a7c
|
|
| BLAKE2b-256 |
6feedda51bb128e197a9fc8b36a93af67046f0a5cc80d36538e8605bf13ba959
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp314-cp314-macosx_10_15_universal2.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp314-cp314-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.14, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
944c7398f593fd449c90252e9a49585107ee1bee0cacac1867e1b9fc9682d7fa
|
|
| MD5 |
674ca19e0ec7bd1a5ab89d6808797ba6
|
|
| BLAKE2b-256 |
85abf04bcc51b45a056a52de0b4e1403125ffdf87191c0a70892744a35515d98
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp313-cp313-win_arm64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp313-cp313-win_arm64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.13, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3f2bb66a392572aefee9807c12e78dbe32f1af02e69e0d04a45175d86ef4a29
|
|
| MD5 |
e478b0082ecc7542a4d173b1ab1744d1
|
|
| BLAKE2b-256 |
04ede3773ebd56f3fb026702dd9863f48c6e850da99a69a9714b9e4a5d210f29
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b64e6f3da7e41ac2bc2485ab7443de80c8779367cf657597f45c972f099a8517
|
|
| MD5 |
6747306fc3d757a6f957db61f52e8931
|
|
| BLAKE2b-256 |
63d49f20c757c4ad1a702ab45bdcf4ce50e6da9178d083c83d6c082b0dd2d24f
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp313-cp313-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp313-cp313-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 6.8 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a0911757875f5d5c365d5899ec57a6acbb7a578305894fb5e6300e227a1ff1d
|
|
| MD5 |
da6b2e83f40f30930148587c18d14873
|
|
| BLAKE2b-256 |
45abb41143ea485d178dbad05ca875a83d8a38311ccf7f519000e13094ee056a
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp313-cp313-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp313-cp313-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 6.7 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f12da8902d40674960e05ed95cc92efb221d232b313167c6db933d06a3c743d2
|
|
| MD5 |
4320cf3d2f27b20ce6abd2dda569f8d0
|
|
| BLAKE2b-256 |
bbf7ece4fc1a8a4c44c00030c5edf125ce0004346db5b5891c86cebc7954ea91
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14dd740bca321b4c5aeb1929a23ca2d68942b133528a9f579a9e895b72c7ce42
|
|
| MD5 |
b2e151829057ba0d2130a83dc72f417d
|
|
| BLAKE2b-256 |
bb661cec2724b19194b98f4bf5b5911c44bdb69bede0f20c6155ccb4113d8b07
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 6.9 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbf92421af78b9d34f47467ae4beab2db2783ccbd8115be568fb233963d1e4d0
|
|
| MD5 |
b02871ca195e1a9ae1d94973894b2deb
|
|
| BLAKE2b-256 |
175d9fcf8500b92ad3a54782fa197102bed6fb9915b1d457e6d102b5f0aa8f1d
|
File details
Details for the file dreaming_electric_sheep-1.0.0-cp313-cp313-macosx_10_13_universal2.whl.
File metadata
- Download URL: dreaming_electric_sheep-1.0.0-cp313-cp313-macosx_10_13_universal2.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.13, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
779462e34e419323cbf405446204b1f92f683765448352574c44b5f03f48a104
|
|
| MD5 |
11a67ac25745e4d6a57cd8ddefa69ebf
|
|
| BLAKE2b-256 |
532b39a17cc3216fe23fcfa46d97c4109824b02d67547f0fe552328901f0e7a2
|