Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

adilkhash/zwsgi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZWSGI

A high-performance WSGI server written in Zig. Run Python web applications (Flask, Django, etc.) with the speed of native code.

Features

  • Fast: Built on http.zig with 140K+ req/sec baseline
  • PEP 3333 Compliant: Full WSGI specification support
  • Multi-threaded: Configurable worker thread pool
  • Virtual Environment Support: Automatically detects and activates Python virtual environments
  • Simple CLI: Gunicorn-like command interface

Requirements

  • Zig 0.15.2+
  • Python 3.11+ with development headers

Installing Python Development Headers

# Debian/Ubuntu
sudo apt install python3-dev

# Fedora
sudo dnf install python3-devel

# macOS (with Homebrew)
brew install [email protected]

# Windows
# Install Python from python.org with "Development files" option

Building

# Clone the repository
git clone https://github.com/yourusername/zwsgi.git
cd zwsgi

# Build
zig build

# The executable will be at ./zig-out/bin/zwsgi

Usage

# Basic usage
zwsgi myapp:application

# With options
zwsgi -b 0.0.0.0 -p 8080 -w 8 myapp.wsgi:application

# With virtual environment (auto-detected from VIRTUAL_ENV)
source venv/bin/activate
zwsgi myapp:application

# With additional Python path
zwsgi --pythonpath /path/to/myapp myapp.wsgi:application

Command Line Options

Option Description Default
-b, --bind ADDRESS Bind address 127.0.0.1
-p, --port PORT Port number 8000
-w, --workers N Number of worker threads 4
--pythonpath PATH Additional Python path -
-h, --help Show help message -

Examples

Simple WSGI Application

# app.py
def application(environ, start_response):
    status = '200 OK'
    headers = [('Content-Type', 'text/plain')]
    start_response(status, headers)
    return [b'Hello, World!\n']
zwsgi app:application

Flask Application

# flask_app.py
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello from Flask!'

application = app
zwsgi flask_app:application

Django Application

zwsgi --pythonpath /path/to/django/project myproject.wsgi:application

Architecture

┌─────────────────────────────────────────────────────────┐
│                      ZWSGI Server                       │
├─────────────────────────────────────────────────────────┤
│  ┌─────────────────────────────────────────────────┐    │
│  │                  http.zig                       │    │
│  │         (HTTP parsing, thread pool)             │    │
│  └─────────────────────────────────────────────────┘    │
│                          │                              │
│                          ▼                              │
│  ┌─────────────────────────────────────────────────┐    │
│  │               WSGI Handler                      │    │
│  │   (environ builder, start_response, iterator)   │    │
│  └─────────────────────────────────────────────────┘    │
│                          │                              │
│                          ▼                              │
│  ┌─────────────────────────────────────────────────┐    │
│  │            Python C API Integration             │    │
│  │        (GIL management, type conversion)        │    │
│  └─────────────────────────────────────────────────┘    │
└──────────────────────────┼──────────────────────────────┘
                           ▼
                ┌──────────────────┐
                │  Python WSGI     │
                │  Application     │
                │  (Flask/Django)  │
                └──────────────────┘

Development

# Build
zig build

# Run tests
zig build test

# Run with arguments
zig build run -- --pythonpath test_apps simple:application

License

MIT

About

WSGI HTTP Server Implemented in Zig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages