jonashaag/bjoern logo

jonashaag/bjoern

Free

A screamingly fast Python 2/3 WSGI server written in C.

FreeFree tier
Type
Open Source

About jonashaag/bjoern

Bjoern is a screamingly fast, ultra-lightweight HTTP/1.1 WSGI server for CPython 2 and CPython 3, written in C using Marc Lehmann's libev event loop and Ryan Dahl's http-parser. It is the fastest, smallest, and most lightweight WSGI server available, featuring approximately 1,000 lines of C code, a memory footprint of around 600KB, and full support for persistent connections (keep-alive) in both HTTP/1.0 and 1.1, including chunked responses. It can bind to TCP host:port addresses and Unix sockets (including abstract Unix sockets on Linux). Installation is via pip install bjoern. The server is single-threaded and avoids coroutines, focusing on minimal overhead and maximum performance.

Key Features

Written in C using libev event loop and http-parser
Ultra-lightweight: ~1000 lines of C code, ~600KB memory footprint
Supports Python 2 and Python 3
Single-threaded, no coroutines or unnecessary overhead
Full persistent connection (keep-alive) support for HTTP/1.0 and HTTP/1.1
Supports chunked responses in HTTP/1.1
Bind to TCP host:port addresses and Unix sockets (including abstract Unix sockets on Linux)
Simple API: bjoern.run(app, host, port) or bjoern.listen() + bjoern.run()
Option to enable SO_REUSEPORT and statsd metrics

Pros & Cons

Pros
  • Extremely fast and lightweight (small memory footprint and minimal code)
  • Written in C for maximum performance
  • Easy installation via pip
  • Supports persistent connections and chunked responses
  • Can bind to both TCP and Unix sockets
Cons
  • Single-threaded; not ideal for CPU-intensive or high-concurrency workloads without external scaling (e.g., multiple processes)
  • Limited to WSGI; no built-in ASGI support
  • No built-in middleware or advanced features like request routing (designed as a pure server)

Best For

Serving Flask or other WSGI-based Python web applications in productionHigh-performance microservices requiring minimal resource usageEmbedded Python web servers with limited memory constraintsSingle-threaded web servers for low-concurrency workloads

FAQ

What is bjoern?
Bjoern is a fast, ultra-lightweight HTTP/1.1 WSGI server for Python 2 and 3, written in C using libev and http-parser. It focuses on minimal overhead and high performance.
How do I install bjoern?
You can install bjoern via pip: pip install bjoern. See the wiki for more details.
Does bjoern support Python 3?
Yes, bjoern supports both CPython 2 and CPython 3.
How do I use bjoern with Flask?
You can run a Flask app with bjoern by importing bjoern and calling bjoern.run(app, '127.0.0.1', 8000) in the script's main block.
Can bjoern bind to Unix sockets?
Yes, bjoern supports binding to Unix sockets (e.g., 'unix:/path/to/socket') and abstract Unix sockets on Linux (e.g., 'unix:@socket_name').