• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convert WSGI app to ASGI app or ASGI app to WSGI app.

a2wsgi

Convert WSGI app to ASGI app or ASGI app to WSGI app.

Pure Python. Only depend on the standard library.

Compared with other converters, the advantage is that a2wsgi will not accumulate the requested content or response content in the memory, so you don't have to worry about the memory limit caused by a2wsgi. This problem exists in converters implemented by uvicorn/startlette or hypercorn.

Install

pip install a2wsgi

How to use

WSGIMiddleware

Convert WSGI app to ASGI app:

from a2wsgi import WSGIMiddleware

ASGI_APP = WSGIMiddleware(WSGI_APP)

WSGIMiddleware executes WSGI applications with a thread pool of up to 10 threads by default. If you want to increase or decrease this number, just like WSGIMiddleware(..., workers=15).

ASGIMiddleware

Convert ASGI app to WSGI app:

from a2wsgi import ASGIMiddleware

WSGI_APP = ASGIMiddleware(ASGI_APP)

ASGIMiddleware will wait for the ASGI application's Background Task to complete before returning the last null byte. But sometimes you may not want to wait indefinitely for the execution of the Background Task of the ASGI application, then you only need to give the parameter ASGIMiddleware(..., wait_time=5.0), after the time exceeds, the ASGI task corresponding to the request will be tried to cancel, and the last null byte will be returned.

You can also specify your own event loop through the loop parameter instead of the default event loop. Like ASGIMiddleware(..., loop=faster_loop)

Access the original Scope/Environ

Sometimes you may need to access the original WSGI Environ in the ASGI application, just use scope["wsgi_environ"]; it is also easy to access the ASGI Scope in the WSGI Application, use environ["asgi.scope"].

Benchmark

Run pytest ./benchmark.py -s to compare the performance of a2wsgi and uvicorn.middleware.wsgi.WSGIMiddleware / asgiref.wsgi.WsgiToAsgi.

Why a2wsgi

Convert WSGI app to ASGI app

You can convert an existing WSGI project to an ASGI project to make it easier to migrate from WSGI applications to ASGI applications.

Convert ASGI app to WSGI app

There is a lot of support for WSGI. Converting ASGI to WSGI, you will be able to use many existing services to deploy ASGI applications.

More Repositories

1

asgi-ratelimit

A ASGI Middleware to rate limit
Python
291
star
2

kui

An easy-to-use web framework. Supports both WSGI and ASGI modes. Gevent or asyncio, this is the question.
Python
279
star
3

rpc.py

A fast and powerful RPC framework based on ASGI/WSGI.
Python
189
star
4

cool

Make Python code cooler. Less is more.
Python
138
star
5

baize

Powerful and exquisite WSGI/ASGI framework/toolkit.
Python
75
star
6

websocks

A proxy server base on websocket
Python
72
star
7

poetry2setup

Convert python-poetry(pyproject.toml) to setup.py.
Python
57
star
8

r2-webdav

Use Cloudflare Workers to provide a WebDav interface for Cloudflare R2.
TypeScript
56
star
9

mingshe

A better Python. It is also a template for you to create a superset of Python.
Python
51
star
10

sync-gitee-mirror

使用 GitHub actions 同步 GitHub 仓库到 Gitee 仓库
16
star
11

china-region-data

中国行政区域数据
Python
14
star
12

pdm-shell

Use `pdm shell` set PATH and PYTHONPATH in the current shell
Python
13
star
13

pep249

Provide minimum implementation check and connection pool of PEP249.
Python
12
star
14

mywxmp

我的微信公众号 ”aber的个人号“
Python
12
star
15

zibai

A modern high-performance pure-Python WSGI server.
Python
11
star
16

setup.py

Poetry-based pypi package template
Python
9
star
17

vless-ws

A cloudflare worker that implements the vless server
TypeScript
8
star
18

runweb

Run web server with one command.
Python
7
star
19

pdm-version

Make `pdm version` like `poetry version`
Python
7
star
20

telegram-bot

Python
7
star
21

coolsql

Makes it easier to write raw SQL in Python.
Python
6
star
22

Ahnu

安徽师范大学相关程序
Python
6
star
23

clash-to-v2rayN

转换 Clash 订阅格式到 v2rayN 订阅格式
TypeScript
6
star
24

rgo-error

Like Rust's `Result` type, but for Go.
Go
5
star
25

localtasks

Google Cloud Tasks Queue substitute in local
Python
5
star
26

asgi-benchmark

Performance comparison between ASGI frameworks
Python
4
star
27

aligi

为阿里无服务函数提供API网关的协议解析
Python
4
star
28

tools-in-web

TypeScript
3
star
29

asynchronous

Efficiently convert synchronous code to asynchronous.
Python
3
star
30

BingImageCreator

High quality image generation by Microsoft. Reverse engineered API.
Python
3
star
31

empty-pypi

empty pypi package
2
star
32

http2tcp

Convert HTTP request to encrypted TCP channel
Go
2
star
33

httpbenchmark

A programmable HTTP stress testing tool. Written in Golang.
Go
2
star
34

mkdocs-version

Simple and easy-to-use mkdocs version plugin based on git tags
Python
2
star
35

qq-group-bot

基于 QQ BOT 平台 API 的群聊机器人
Python
2
star
36

compose.yaml

1
star
37

issue

Filter logs by name. Allow Unix shell style wildcards.
Python
1
star
38

rust-h11

A pure-Rust, bring-your-own-I/O implementation of HTTP/1.1
Rust
1
star
39

abersheeran

1
star
40

blog-comments

Comments for my blog
1
star
41

typeddict

Use `TypedDict` replace pydantic definitions.
Python
1
star
42

kjango

Use kui with django orm/admin/or other anything.
1
star