Skip to main content

Bringing WebSockets, Http/Https High Performance servers for PyPy3 and Python3

Project description

socketify.py (delian-socketify)

Logo

PyPI

Github   •   Issues   •   Examples

This is a maintained fork of cirospaciari/socketify.py published to PyPI as delian-socketify. The Python import name remains socketify, so existing code keeps working unchanged. All credit for the original work goes to Ciro Spaciari and contributors; this fork only packages and maintains it under a new distribution name.

💡 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

:mag_right: 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

:zap: 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 delian-socketify
#or specify PyPy3
pypy3 -m pip install delian-socketify
#or in editable mode
pypy3 -m pip install -e .

Using install via requirements.txt

delian-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

:hammer: Building from source

#clone and update submodules
git clone https://github.com/Delian-Alliance-Industries/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 delian-socketify

:page_facing_up: Attribution

Original project: cirospaciari/socketify.py by Ciro Spaciari. Licensed under the MIT License (see LICENSE).

Special thanks to uNetworking AB for uWebSockets and uSockets, which power this library.

:grey_question: uvloop

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

:dizzy: CFFI vs Cython vs HPy

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

delian_socketify-0.1.1.tar.gz (6.4 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

delian_socketify-0.1.1-cp313-cp313-win_amd64.whl (961.6 kB view details)

Uploaded CPython 3.13Windows x86-64

delian_socketify-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

delian_socketify-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

delian_socketify-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

delian_socketify-0.1.1-cp311-cp311-win_amd64.whl (961.6 kB view details)

Uploaded CPython 3.11Windows x86-64

delian_socketify-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

delian_socketify-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

delian_socketify-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

delian_socketify-0.1.1-cp39-cp39-win_amd64.whl (961.6 kB view details)

Uploaded CPython 3.9Windows x86-64

delian_socketify-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

delian_socketify-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

delian_socketify-0.1.1-cp39-cp39-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file delian_socketify-0.1.1.tar.gz.

File metadata

  • Download URL: delian_socketify-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for delian_socketify-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0e590f0d0594c39107ffa3ab8927bcdb962e31833a0bd23679dea561f313e544
MD5 ff9a33f91f36da74893de70d474555ee
BLAKE2b-256 7eeab0b44a75f13505abf57ab30eadbe4dabfaefca569a25bfdfb699568a6c68

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1.tar.gz:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d5089adcd20d25a894495e183619c8abcc7d8950e4e7812abc5290a7b0e95f2a
MD5 739f8bcafaf5a3aa9644e73d03cdebc2
BLAKE2b-256 0de7480ec33ed5183f78a156a0f558e56e21b863c463887a9ca2f807e2804bce

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp313-cp313-win_amd64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1bd88319468264372f4a5791f85424066d5f9a8ce736b5c3d38b47effd8ae781
MD5 6c73f4708313306848a7725f9baea085
BLAKE2b-256 cdf64ec6f32a2d25bcc94977919e855b33b55e7462a1db1ef968be3410917a21

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d461c424c3081710c8650737461383e34dcbae67c8ad22ffd692dda8dce084dd
MD5 36bcf76b1149366a30835c60aa64720f
BLAKE2b-256 65f419ef2193ca17bdd780d8c84a1700ef717d1af1e44fe9833acbc97cbd0c71

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8597f79f86c0f8e37994dc6b4123445d86d25c803b0c0ff1707da78f7b317e3a
MD5 d3a193e500496aa20eb2de4a25905acd
BLAKE2b-256 718cd69912553bf4737fd921a62c9e192efc0999400694347e54802658813e14

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cb8a512f9c6d6ab98ec3487431e531ed7f60b7102f3231b26f15f047f7fbd05a
MD5 e58b539dac587810196e39a3a70cd6d1
BLAKE2b-256 4a27763ad1679c5b03b108c250402373da6e53f02f8eb02752554094f9bcbe6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp311-cp311-win_amd64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 07c89b401ff59e3e58d9709d09a35d2f287024759d81487a8556b35a25659c52
MD5 5aa2640cc0da3fd0cb18ddfcb0ba68c7
BLAKE2b-256 5694d7f1ae706b25131fab6487e8b11c387bd128299090a697d9e29649acdee6

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c7f251c6bf0003aadcbd4b8c0bae4188063d8a6b12600bf9a82fef3314445356
MD5 bf65f3a1b0df9e8c38d123ca929e1182
BLAKE2b-256 60ea66113f6f5769690a4420cde19afcbd3cbeed295a9d6afb3f4b2733b0bd49

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b5c3ccfad3f8a8b1b9fcd5b907e58564686e6d9bb290f5e9de6b7d162a999c8
MD5 7ed9f757fd6eec66a849f51770d32b93
BLAKE2b-256 cdf920a18215a6194b290b295aeda658f972d8a8c3d4231be5f60056c1f749d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d77a44eac8b918fd798059c9e53bf61f74a01900892e9160b0257276e1d450fe
MD5 786e1bdf02d5acea5b63be70c83db6c7
BLAKE2b-256 84fc45aa5b5acf43b149ee0b5df5df2601d5005772f2d6b7c1fcde8c87f52e7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp39-cp39-win_amd64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b82b50c442e5c86fb7a05ca52581cd01f214fcf967502b1a82545ead5eb87732
MD5 1dec542a6c461b1aab8e6ee5492c87cf
BLAKE2b-256 842e8212672f1e12f2b2abaab62d90b98a0a82cf700ecaf320c595a282d0eea0

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 973bfe1d0eb204fdd61eba0a5f5e174dae36d42c1138cb96790d18e23030b314
MD5 ddfbbd35d2c06e2ef96c32071e2ebd8d
BLAKE2b-256 c1e58d888c5eb6adff5e02684c268b56c88939325a93a7f040acc08c72cbf00c

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delian_socketify-0.1.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for delian_socketify-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e087a3d0a75be228e1ab7d6451b56dd967c79b363ca3f1f51a1581c881445ccd
MD5 d5d80313a5abe86639031ae0c256877c
BLAKE2b-256 cc2cec64cc5a3615d1a70f6091a4e4e7c9a22e629e4278f00efd2ac8c9ce7c5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for delian_socketify-0.1.1-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: release.yml on Delian-Alliance-Industries/socketify.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page