Socketify.py - Maybe the fastest web framework for Python and PyPy

Socketify.py - Maybe the fastest web framework for Python and PyPy

Really fast http and websockets for Python, PyPy3 and more

This year i started a journey to bring a really fast framework for Http, Http2, Http3 and WebSockets to Python and PyPy.

The problems with japronto and uvloop

Japronto don't get any github updates since 2020 and don't get any src update since 2018, japronto don't support SSL, WebSockets, PyPy3, Windows or macOS Silicon. I really needed good support + performance, not only performance. Almost any solution out there have a really big performance hit when using PyPy3 or are not really fast enougth

The Solution

We discover a really fast, small, and well maintained C++ Library called uNetworking/uWebSockets, but no C API available, so we create and adapt the full C API from uNetworking/uWebSockets and will integrate libuv powered fetch and file IO, this same C API is used by Bun

Benchmarking

We got about 770k req/s with the current version vs 582k from japronto using TechEmPower plaintext benchmarks and we still can get at least 30% or more performance once fully integrated with libuv + asyncio.

Socketify.py brings:

  • WebSocket with pub/sub support
  • Fast and realiable Http/Https
  • Support for Windows, Linux and macOS Silicon & x64
  • Support for PyPy3 and CPython

This project aims to bring high performance PyPy3 web development and will bring:

  • Fetch like API powered by libuv
  • Async file IO powered by libuv
  • Full asyncio integration with libuv
  • Full Http3 support
  • HPy integration to better support CPython, PyPy and GraalPython

Install

For macOS x64 & Silicon, Linux x64, Windows

pip install git+https://github.com/cirospaciari/socketify.py.git
#or specify PyPy3
pypy3 -m pip install git+https://github.com/cirospaciari/socketify.py.git
#or in editable mode
pypy3 -m pip install -e git+https://github.com/cirospaciari/socketify.py.git@main#egg=socketify

Code Example

from socketify import App, AppOptions

app = App(AppOptions(key_file_name="./misc/key.pem", cert_file_name="./misc/cert.pem", passphrase="1234"))
app.get("/", lambda res, req: res.end("Hello World socketify from Python!"))
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
app.run()

Support

Socketify is an active project and will be maintained over time with security updates and new features and will be commercial support available

Check our github page: github.com/cirospaciari/socketify.py