Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

cirospaciari/socketify.py

Repository files navigation

Logo

GitHub ClonesPyPI DownloadsDiscord

Documentation  •  Discord  •  Issues  •  Examples

💡 Features

  • WebSocket with pub/sub support
  • Fast and reliable Http/Https
  • Support for Windows, Linux and macOS Silicon & x64
  • Support forPyPy3 andCPython
  • 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 withMako andJinja2)
  • 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 supportCPython,PyPy andGraalPython
  • Hot Reloading

We created and adapted the full C API fromuNetworking/uWebSockets and will integrate libuv powered fetch and file IO, this same C API is used byBun

Join GithubDiscussions orDiscord 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 withBun.sh bench chat-client
Source code inTechEmPower and for websockets inbench

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 PyPy3pypy3 -m pip install socketify#or in editable modepypy3 -m pip install -e socketify

Using install via requirements.txt

socketify
pip install -r ./requirements.txt#or specify PyPy3pypy3 -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 libuvbrew install zlib

Linux (Ubuntu/Debian)

apt install libuv1 zlib1g

Linux (RHEL/OEL)

yum install cmake zlib-devel libuv-devel

🤔 Usage

Hello world app

fromsocketifyimportAppapp=App()app.get("/",lambdares,req:res.end("Hello World socketify from Python!"))app.listen(3000,lambdaconfig:print("Listening on port http://localhost:%d now\n"%config.port))app.run()

SSL version sample

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

WebSockets

fromsocketifyimportApp,OpCode,CompressOptionsdefws_open(ws):print('A WebSocket got connected!')ws.send("Hello World!",OpCode.TEXT)defws_message(ws,message,opcode):#Ok is false if backpressure was built up, wait for drainok=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':lambdaws:print(f'WebSocket backpressure:{ws.get_buffered_amount()}'),'close':lambdaws,code,message:print('WebSocket closed'),'subscription':lambdaws,topic,subscriptions,subscriptions_before:print(f'subscribe/unsubscribe on topic{topic}{subscriptions}{subscriptions_before}'),})app.any("/",lambdares,req:res.end("Nothing to see here!'"))app.listen(3000,lambdaconfig:print("Listening on port http://localhost:%d now\n"% (config.port)))app.run()

We have more than 20 examplesclick here for more

🔨 Building from source

#clone and update submodulesgit clone https://github.com/cirospaciari/socketify.py.gitcd ./socketify.pygit submodule update --init --recursive --remote#you can use make linux, make macos or call Make.bat from Visual Studio Development Prompt to buildcd ./src/socketify/native/&& make linux&&cd ../../../#install local pippypy3 -m pip install.#install in editable modepypy3 -m pip install -e.#if you want to removepypy3 -m pip uninstall socketify

💼 Commercially supported

I'm a Brazilian consulting & contracting company dealing with anything related withsocketify.py andsocketify.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 touNetworking AB to developuWebSockets,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 youOtavio 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 stableHPy integration.

Sponsor this project

 

[8]ページ先頭

©2009-2025 Movatter.jp