• Stars
    star
    1,142
  • Rank 40,813 (Top 0.9 %)
  • Language
    Python
  • License
    MIT License
  • Created over 2 years ago
  • Updated 12 months ago

Reviews

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

Repository Details

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

socketify.py

Logo


GitHub Clones PyPI Downloads Discord

๐Ÿ“‘ Documentation

See the full docs in docs.socketify.dev or in /docs/README.md

Also take a look in the examples in /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

apt install libuv1 zlib1g

๐Ÿค” 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, AppOptions, 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'subscription/unsubscription 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

โ“ socketify.py vs japronto

People really want to compare with japronto, but this projects are not really comparable. Socketify is an active project and will be maintained over time with security updates and new features, 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, socketify will support Http3 and a lot more features.

And yes, we can be faster than japronto when all our features and goals are achieved, and we are probably faster than any current maintained solution out there.

โ” 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 an stable HPy integration.

More Repositories

1

jscomet

Create apps and a fast MVC website with OO class like ES6/TypeScript/Babel features with truly private vars and functions, type validations, function overloads, all in runtime and create libraries like browserify and reference this in your projects.
JavaScript
15
star
2

format-helper

Helper multi idioma para formataรงรตes com data, hora, valores, moedas e timespan.
JavaScript
10
star
3

crunchyroll.tv

WebOS app for crunchyroll
JavaScript
6
star
4

socketify.rb

Bringing WebSockets, Http/Https High Peformance servers for Ruby
C
6
star
5

jscomet.core

Contain features MVC for web, Desktop and Mobile Apps to use with JSComet
JavaScript
4
star
6

jscomet.decorators

Here are some examples of implementing decorators using jscomet. The implementation of decorators used by js comet does not follow ES6 / ES7 in the future adaptations will be made for compatibility
JavaScript
4
star
7

storeclouding.aspects

Helper for MemoryCache and HttpRequest using PostSharp
C#
3
star
8

jscomet.game

Simple Game engine created using JSComet
JavaScript
3
star
9

fastify-twig

Twig view renderer for fastify
JavaScript
2
star
10

simple

Simple parser and interpreter
JavaScript
1
star
11

create-react-renderer

Just a blank slate for SSR with @react-renderer/router and @react-renderer/app
JavaScript
1
star
12

jscomet.editor

Editor for JSComet projects
CSS
1
star
13

cordova-base-vue3

JavaScript
1
star
14

react-renderer-app

JavaScript
1
star
15

fastify-vash

Vash view renderer for fastify
JavaScript
1
star
16

storeclouding.sandboxengine

SandBox Game Engine based in unity
C#
1
star
17

word.generator

Generate a random array of english words
JavaScript
1
star
18

genetic-evolution-simulator

Just some tests of simulations based in neurons and connections/genes and survival conditions for simple enemy AI
JavaScript
1
star
19

vue3-webpack-fastify-eta-test

Just a Test With Vue3 and WebPack + Fastify and Eta
JavaScript
1
star
20

jsdirective

Html preprocessor like Angular but more simple just for studies
JavaScript
1
star