Skip to main content

socketify.py

Logo


GitHub Clones PyPI Downloads Discord

Documentation   •   Discord   •   Issues   •   Examples

💡 Features

  • WebSocket with pub/sub support
  • Fast and reliable Http/Https
  • Support for Windows, Linux and macOS Silicon & x64
  • Support for PyPy3 and CPython
  • Dynamic URL Routing with Wildcard & Parameter support
  • Sync and Async Function Support
  • Really Simple API
  • Fast and Encrypted TLS 1.3 quicker than most alternative servers can do even unencrypted, cleartext messaging
  • Per-SNI HttpRouter Support
  • Proxy Protocol v2
  • Shared or Dedicated Compression Support
  • Max Backpressure, Max Timeout, Max Payload and Idle Timeout Support
  • Automatic Ping / Pong Support
  • Per Socket Data
  • Middlewares
  • Templates Support (examples with Mako and Jinja2)
  • ASGI Server
  • WSGI Server
  • Plugins/Extensions

🔎 Upcoming Features

  • In-Memory Cache Tools
  • Fetch like API powered by libuv
  • Async file IO powered by libuv
  • Full asyncio integration with libuv
  • SSGI Server spec and support
  • RSGI Server support
  • Full Http3 support
  • HPy integration to better support CPython, PyPy and GraalPython
  • Hot Reloading

We created and adapted the full C API from uNetworking/uWebSockets and will integrate libuv powered fetch and file IO, this same C API is used by Bun

Join Github Discussions or Discord for help and have a look at the development progress.

⚡ Benchmarks

Socketify WebFramework HTTP requests per second (Linux x64)

image

WSGI Server requests per second (Linux x64)

image

ASGI Server requests per second (Linux x64)

image

WebSocket messages per second (Linux x64)

image

Http tested with TFB tool plaintext benchmark
WebSocket tested with Bun.sh bench chat-client
Source code in TechEmPower and for websockets in bench

Machine OS: Debian GNU/Linux bookworm/sid x86_64 Kernel: 6.0.0-2-amd64 CPU: Intel i7-7700HQ (8) @ 3.800GHz Memory: 32066MiB

📦 Installation

For macOS x64 & Silicon, Linux x64, Windows

pip install socketify
#or specify PyPy3
pypy3 -m pip install socketify
#or in editable mode
pypy3 -m pip install -e socketify

Using install via requirements.txt

socketify
pip install -r ./requirements.txt 
#or specify PyPy3
pypy3 -m pip install -r ./requirements.txt 

If you are using linux or macOS, you may need to install libuv and zlib in your system

macOS

brew install libuv
brew install zlib

Linux (Ubuntu/Debian)

apt install libuv1 zlib1g

Linux (RHEL/OEL)

yum install cmake zlib-devel libuv-devel

🤔 Usage

Hello world app

from socketify import App

app = App()
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()

SSL version sample

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()

WebSockets

from socketify import App, OpCode, CompressOptions

def ws_open(ws):
    print('A WebSocket got connected!')
    ws.send("Hello World!", OpCode.TEXT)

def ws_message(ws, message, opcode):
    #Ok is false if backpressure was built up, wait for drain
    ok = ws.send(message, opcode)
    
app = App()    
app.ws("/*", {
    'compression': CompressOptions.SHARED_COMPRESSOR,
    'max_payload_length': 16 * 1024 * 1024,
    'idle_timeout': 12,
    'open': ws_open,
    'message': ws_message,
    'drain': lambda ws: print(f'WebSocket backpressure: {ws.get_buffered_amount()}'),
    'close': lambda ws, code, message: print('WebSocket closed'),
    'subscription': lambda ws, topic, subscriptions, subscriptions_before: print(f'subscribe/unsubscribe on topic {topic} {subscriptions} {subscriptions_before}'),
})
app.any("/", lambda res,req: res.end("Nothing to see here!'"))
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % (config.port)))
app.run()

We have more than 20 examples click here for more

🔨 Building from source

#clone and update submodules
git clone https://github.com/cirospaciari/socketify.py.git
cd ./socketify.py
git submodule update --init --recursive --remote
#you can use make linux, make macos or call Make.bat from Visual Studio Development Prompt to build
cd ./src/socketify/native/ && make linux && cd ../../../
#install local pip
pypy3 -m pip install .
#install in editable mode
pypy3 -m pip install -e .
#if you want to remove
pypy3 -m pip uninstall socketify

💼 Commercially supported

I'm a Brazilian consulting & contracting company dealing with anything related with socketify.py and socketify.rb

Don't hesitate sending a mail if you are in need of advice, support, or having other business inquiries in mind. We'll figure out what's best for both parties.

Special thank's to uNetworking AB to develop uWebSockets, uSockets and allow us to bring this features and performance to Python and PyPy

❤️ Sponsors

If you like to see this project thrive, you can sponsor us on GitHub too. We need all the help we can get.

Thank you Otavio Augusto to be the first sponsor of this project!

⭐ Stargazers

Stargazers repo roster for @cirospaciari/socketify.py

🔧 Forkers

Forkers repo roster for @cirospaciari/socketify.py

❔ uvloop

We don't use uvloop, because uvloop don't support Windows and PyPy3 at this moment, this can change in the future, but right now we want to implement our own libuv + asyncio solution, and a lot more.

💫 CFFI vs Cython vs HPy

Cython performs really well on Python3 but really bad on PyPy3, CFFI are chosen for better support PyPy3 until we got our hands on a stable HPy integration.

Release files for socketify 0.0.31

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for socketify 0.0.31
File Size Uploaded
socketify-0.0.31.tar.gz 4.9 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for socketify 0.0.31
File Interpreter ABI Platform
socketify-0.0.31-pp310-pypy310_pp73-any.whl PyPy 3.10 PyPy 3.10 7.3 any Details
socketify-0.0.31-cp313-cp313-any.whl CPython 3.13 CPython 3.13 any Details

Total release size: 14.6 MB

Release files / socketify-0.0.31.tar.gz

Download URL socketify-0.0.31.tar.gz
Size 4.9 MB
Tags Source
SHA-256 checksum
How to use checksums
7502bed5b382e75f04ea3c6d6b53b76f27bb8653740db92e3f2b55fab388df20
BLAKE2b-256 checksum
How to use checksums
ef74c7ba0eadc4946de73c7146d6750542fda9b47883e6aaedadef88c1aba94e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / socketify-0.0.31-pp310-pypy310_pp73-any.whl

Download URL socketify-0.0.31-pp310-pypy310_pp73-any.whl
Size 4.9 MB
Tags PyPy 3.10 PyPy 3.10 7.3
SHA-256 checksum
How to use checksums
379f109a87edf396ed513869ee921a70cf8f4694ce7ef347d414c72e2543c954
BLAKE2b-256 checksum
How to use checksums
970c302372aee5ab9d33c9edf9f881add00b5995677bde32d37f5b6edd79be89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / socketify-0.0.31-cp313-cp313-any.whl

Download URL socketify-0.0.31-cp313-cp313-any.whl
Size 4.9 MB
Tags CPython 3.13
SHA-256 checksum
How to use checksums
328e6e46f8a896e09400fd415c8d402b9da40a0a154c4bb4ac0d851d54d380c0
BLAKE2b-256 checksum
How to use checksums
e388a9cac856802aace439aa7cce52924c3cf2da1d684509d9c4135f401b244b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

0.0.31 This release

3 release files

0.0.30

3 release files

0.0.29

3 release files

0.0.28

3 release files

0.0.27

3 release files

0.0.26

3 release files

0.0.25

3 release files

0.0.24

3 release files

0.0.21

2 release files

0.0.20

3 release files

0.0.19

3 release files

0.0.18

3 release files

0.0.17

3 release files

0.0.16

3 release files

0.0.11

3 release files

0.0.10

3 release files

0.0.9

3 release files

0.0.8

3 release files

0.0.7

3 release files

0.0.6

3 release files

0.0.5

3 release files

0.0.4

3 release files

0.0.3

3 release files

0.0.2

3 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page