Metadata-Version: 2.4
Name: bessemer
Version: 1.0.0rc13
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
Classifier: Programming Language :: Rust
Requires-Dist: ag-ui-protocol>=1,<2 ; extra == 'ag-ui'
Requires-Dist: maturin==1.16.0 ; extra == 'dev'
Requires-Dist: ruff==0.17.3 ; extra == 'dev'
Requires-Dist: opentelemetry-api==1.45.2 ; extra == 'dev'
Requires-Dist: opentelemetry-api>=1.27,<2 ; extra == 'otel'
Requires-Dist: pydantic>=2.10.6,<3 ; extra == 'pydantic'
Provides-Extra: ag-ui
Provides-Extra: dev
Provides-Extra: otel
Provides-Extra: pydantic
License-File: LICENSE-MIT
License-File: LICENSE-APACHE
Summary: A Rust HTTP runtime with a Python application API
License-Expression: MIT OR Apache-2.0
Requires-Python: >=3.12
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Changelog, https://github.com/CodeHalwell/bessemer/blob/main/CHANGELOG.md
Project-URL: Documentation, https://github.com/CodeHalwell/bessemer/tree/main/docs
Project-URL: Repository, https://github.com/CodeHalwell/bessemer

# Bessemer

![Bessemer: Rust HTTP runtime with a Python API](https://raw.githubusercontent.com/CodeHalwell/bessemer/main/docs/assets/bessemer-readme-banner.png)

**Build a typed Python API and serve it with a Rust HTTP runtime.** Write
handlers with decorators, type hints, and ordinary Python functions.
Bessemer runs the HTTP server and worker supervisor, with native routing,
input parsing, and JSON encoding on supported request paths.

**Up to 13.15× FastAPI throughput** on one pinned Linux worker in the
published RC12 benchmark. That result came from a typed path/query route,
the kind of endpoint you can write in a few lines. [GCP benchmark report](https://github.com/CodeHalwell/bessemer/blob/main/benchmarks/results/2026-11-30/gcp-rc12-published/report.md)

## Quick start

Save this as `app.py`.

```python
from bessemer import App, Query

app = App(title="Inventory API", docs_url="/docs")
app.health("/healthz")


@app.get("/items/{item_id}")
async def get_item(item_id: int, quantity: int = Query(1, ge=1, le=100)):
    return {"item_id": item_id, "quantity": quantity}
```

Start the server from the same directory with `uvx`. This pins the
RC13 release candidate and uses standard CPython 3.13.
[Install uv](https://docs.astral.sh/uv/getting-started/installation/)

```sh
uvx --python 3.13 --from 'bessemer==1.0.0rc13' bessemer run app:app \
  --host 127.0.0.1 --port 8000 --workers 1
```

In another terminal:

```sh
curl -fsS 'http://127.0.0.1:8000/items/42?quantity=3'
```

```json
{"item_id":42,"quantity":3}
```

The type hints give the handler integers. The `Query` constraint limits
quantity to 1–100, and the same route declaration generates an OpenAPI
schema. Open the bundled reference at `http://127.0.0.1:8000/docs`. The
runtime serves `/healthz` directly in Rust. [Application API](https://github.com/CodeHalwell/bessemer/blob/main/docs/application-api.md)

## Performance

On the same GCP server with four pinned workers, median round p99 for
small JSON was **0.380 ms** on Bessemer and **2.799 ms** on FastAPI.

| Four-worker workload | Bessemer RC12 replies/s | FastAPI replies/s | RC12 / FastAPI |
| --- | ---: | ---: | ---: |
| Small JSON | 302,827 | 41,588 | 7.28× |
| Typed path and query | 295,925 | 32,591 | 9.08× |
| 20-item typed JSON echo | 143,146 | 24,849 | 5.76× |
| 1,000-item typed JSON echo | 6,713 | 1,784 | 3.75× |
| 256-model response | 80,596 | 13,295 | 6.06× |

These are medians from the published RC12 Linux x86-64 wheel and FastAPI
0.165.0 with Uvicorn, uvloop, and httptools. The comparison used standard
CPython 3.14.7, HTTP/1.1 keep-alive, a GCP C3 server, and a separate load
generator. The last column uses paired rounds. The four-worker CPU
checksums ran at 1.04–1.12× FastAPI across both Python builds, and 256 KiB
downloads were near parity. [Full matrix and sample data](https://github.com/CodeHalwell/bessemer/blob/main/benchmarks/results/2026-11-30/gcp-rc12-published/matrix.md) ·
[Reproduce the benchmark](https://github.com/CodeHalwell/bessemer/blob/main/benchmarks/results/2026-11-30/gcp-rc12-published/reproduction.md)

The same study tested the published RC11 wheel and free-threaded Python
3.14t. Paired p99 for the 1,000-item echo was 18.1% lower on standard
Python and 15.2% lower on free-threaded Python in RC12 versus RC11.
[RC12 release comparison](https://github.com/CodeHalwell/bessemer/blob/main/benchmarks/results/2026-11-30/gcp-rc12-published/report.md)

## Coming from FastAPI

Start with familiar route decorators, `APIRouter`, `Depends`, and
Pydantic models. `bessemer.FastAPI` is an alias for `bessemer.App`, so
you can keep those names as you port routes.

```python
from bessemer import APIRouter, Depends, FastAPI

app = FastAPI(title="Inventory API", docs_url="/docs")
router = APIRouter(prefix="/inventory")


def warehouse() -> str:
    return "north"


@router.get("/items/{item_id}")
async def get_item(item_id: int, location: str = Depends(warehouse)):
    return {"item_id": item_id, "warehouse": location}


app.include_router(router)
```

Bessemer builds the route table and handler signatures at startup. Rust
matches the route and handles supported scalar and JSON work. Your handler
and dependency functions execute in Python, and Pydantic handles model
validation when the route needs its full semantics. You can mount an ASGI
app to keep existing routes available while you port others.
[FastAPI compatibility and porting guide](https://github.com/CodeHalwell/bessemer/blob/main/docs/fastapi-parity.md)

## Run it under load

- **Supervise workers with the server.** `bessemer run` starts worker
  processes, tracks readiness and heartbeats, restarts failed workers,
  and drains connections at shutdown. Linux workers can share a listener
  and balance bursts of new connections. [Worker supervision](https://github.com/CodeHalwell/bessemer/blob/main/docs/supervision.md)
- **Set limits on in-flight work.** Bound connections, request time, and
  the memory held by request and response payloads. The runtime also
  supports native API-key checks, rate limits, and protected metrics.
  [Production controls](https://github.com/CodeHalwell/bessemer/blob/main/docs/production-controls.md)
- **Keep long-lived connections in the same app.** Serve HTTP/1.1 and
  HTTP/2, stream responses or server-sent events, and handle bidirectional
  WebSockets. The AG-UI adapter supports SSE and a WebSocket transport
  with live input and cancellation. [AG-UI guide](https://github.com/CodeHalwell/bessemer/blob/main/docs/ag-ui.md)

Linux x86-64 is the qualified production platform. Published wheels cover
CPython 3.12–3.14 and 3.14t on Linux x86-64, and CPython 3.12–3.13 on
macOS arm64 and x86-64 and Windows x86-64. Bessemer is a 1.0 release
candidate with a frozen public API for 1.x. Source builds require Rust
1.92 or newer. [PyPI release files](https://pypi.org/project/bessemer/1.0.0rc13/) ·
[Production readiness](https://github.com/CodeHalwell/bessemer/blob/main/docs/production-readiness.md)

## Documentation

- [Application API and production example](https://github.com/CodeHalwell/bessemer/blob/main/docs/application-api.md)
- [Container deployment and qualification](https://github.com/CodeHalwell/bessemer/blob/main/docs/deployment.md)
- [Earlier GCP benchmark with native Axum](https://github.com/CodeHalwell/bessemer/blob/main/benchmarks/results/2026-11-24/gcp-main-678e318/report.md)
- [Workload cost and capacity analysis](https://github.com/CodeHalwell/bessemer/blob/main/docs/performance-cost.md)
- [Changelog](https://github.com/CodeHalwell/bessemer/blob/main/CHANGELOG.md) ·
  [Releases](https://github.com/CodeHalwell/bessemer/releases) ·
  [Security policy](https://github.com/CodeHalwell/bessemer/blob/main/SECURITY.md)

## Development

From the checkout, install the native package and run the project checks.

```sh
uv venv --python 3.13
source .venv/bin/activate
uv pip install '.[dev,pydantic]'
BESSEMER_REQUIRE_NATIVE=1 ./scripts/check.sh
```

The repository also includes the original M0 experiment comparing a Rust
handler with a Python handler driven through PyO3. Try its local paired
runner with `DURATION=1s CONNECTIONS=25 ./benchmarks/run_m0.sh`. This is an
exploratory smoke run. The formal performance gate remains open.
[Technical specification](https://github.com/CodeHalwell/bessemer/blob/main/docs/technical-specification.md) ·
[M0 measurement harness](https://github.com/CodeHalwell/bessemer/blob/main/benchmarks/measure_m0.py)

## Licence

Bessemer is licensed under either of [Apache License, Version 2.0](https://github.com/CodeHalwell/bessemer/blob/main/LICENSE-APACHE)
or [MIT license](https://github.com/CodeHalwell/bessemer/blob/main/LICENSE-MIT), at your option. Unless you explicitly state
otherwise, any contribution intentionally submitted for inclusion in Bessemer,
as defined in the Apache-2.0 licence, is dual licensed as above, without any
additional terms or conditions.

