socketify.py/README.md

129 wiersze
6.7 KiB
Markdown
Czysty Zwykły widok Historia

2022-05-28 13:47:26 +00:00
# socketify.py
2022-11-05 15:58:00 +00:00
2022-05-24 19:37:16 +00:00
2022-11-08 11:25:54 +00:00
<p align="center">
2022-11-08 11:26:40 +00:00
<a href="https://github.com/cirospaciari/socketify.py"><img src="https://raw.githubusercontent.com/cirospaciari/socketify.py/main/misc/logo.png" alt="Logo" height=170></a>
2022-11-08 11:25:54 +00:00
<br />
<br />
<a href="https://github.com/cirospaciari/socketify.py/actions/workflows/macos.yml" target="_blank"><img src="https://github.com/cirospaciari/socketify.py/actions/workflows/macos.yml/badge.svg" /></a>
<a href="https://github.com/cirospaciari/socketify.py/actions/workflows/linux.yml" target="_blank"><img src="https://github.com/cirospaciari/socketify.py/actions/workflows/linux.yml/badge.svg" /></a>
<a href="https://github.com/cirospaciari/socketify.py/actions/workflows/windows.yml" target="_blank"><img src="https://github.com/cirospaciari/socketify.py/actions/workflows/windows.yml/badge.svg" /></a>
</p>
2022-05-24 19:37:16 +00:00
2022-10-11 12:33:55 +00:00
2022-11-08 11:25:54 +00:00
socketify.py brings:
- WebSocket with pub/sub support
- Fast and realiable Http/Https
- Support for Windows, Linux and macOS Silicon & x64
- Support for [`PyPy3`](https://www.pypy.org/) and [`CPython`](https://github.com/python/cpython)
This project aims to bring high performance PyPy3 web development and will bring:
2022-11-08 14:06:18 +00:00
- Fetch like API powered by libuv
- Async file IO powered by libuv
- Full asyncio integration with libuv
- Full Http3 support
2022-11-08 14:15:37 +00:00
- [`HPy`](https://hpyproject.org/) integration to better support [`CPython`](https://github.com/python/cpython), [`PyPy`](https://www.pypy.org/) and [`GraalPython`](https://github.com/oracle/graalpython)
2022-11-08 11:25:54 +00:00
2022-11-08 14:27:09 +00:00
We created and adapt the full C API from [uNetworking/uWebSockets](https://github.com/uNetworking/uWebSockets) and will integrate libuv powered fetch and file IO, this same C API is used by [Bun](https://bun.sh/)
2022-11-08 11:25:54 +00:00
2022-11-08 14:36:04 +00:00
**socketify is experimental software at the moment, but quickly heading towards its first release**. Join Github Discussions for help and have a look at things that dont work yet.
2022-11-08 14:06:18 +00:00
## socketify.py vs japronto
2022-11-08 14:15:37 +00:00
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`](https://www.pypy.org/), 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 choosen for better support PyPy3 until we got our hands on an stable [`HPy`](https://hpyproject.org/) integration.
2022-11-08 14:06:18 +00:00
## Benchmarks
2022-11-08 13:07:18 +00:00
HTTP requests per second (Linux x64)
2022-11-08 13:35:34 +00:00
| framework | req/s | runtime |
2022-11-08 13:19:34 +00:00
| ------------- | -------------: | :-------------: |
| socketify.py | 124,943 | PyPy3 |
| socketify.py | 70,877 | Python3 |
| uvicorn | 30,173 | Python3 |
| uvicorn | 17,580 | PyPy3 |
2022-11-08 13:07:18 +00:00
Runtime versions: PyPy3 7.3.9 and Python 3.10.7<br/>
Framework versions: gunicorn 20.1.0 + uvicorn 0.19.0, socketify alpha<br/>
Tested with ./http_load_test 40 127.0.0.1 8000 from [uSockets](https://github.com/uNetworking/uSockets)
Source code in [bench](https://github.com/cirospaciari/socketify.py/tree/main/bench)
2022-11-08 13:38:25 +00:00
> Today socketify have about 30% performance hit due to workarounds between asyncio + libuv, so we will got even faster! See more info in [this issue](https://github.com/cirospaciari/socketify.py/issues/18), in PyPy3 we can get about 186,760 req/s and 77,774 req/s in Python3 without these workarounds and almost double of the scores with PyPy3 in TechEmPower plaintext, Python3 and PyPy3 performance will improve when we migrate to [HPy](https://github.com/cirospaciari/socketify.py/issues/16). In TechEmPower benchmarks we are faster than japronto in plaintext (about 1,300k req/s using PyPy3 without workaround and about 770k req/s with the current state vs 582k from japronto you can follow details in [this discussion](https://github.com/cirospaciari/socketify.py/discussions/10)
2022-11-08 11:25:54 +00:00
2022-11-08 11:34:26 +00:00
## Install
For macOS x64 & Silicon, Linux x64, Windows
2022-05-24 19:37:16 +00:00
```bash
2022-11-04 23:08:20 +00:00
pip install git+https://github.com/cirospaciari/socketify.py.git
2022-05-28 20:04:35 +00:00
#or specify PyPy3
2022-11-04 23:08:20 +00:00
pypy3 -m pip install git+https://github.com/cirospaciari/socketify.py.git
2022-05-29 00:00:21 +00:00
#or in editable mode
pypy3 -m pip install -e git+https://github.com/cirospaciari/socketify.py.git@main#egg=socketify
2022-05-24 19:37:16 +00:00
```
2022-11-08 11:34:26 +00:00
Using install via requirements.txt
2022-05-29 00:00:21 +00:00
```text
2022-11-04 23:08:20 +00:00
git+https://github.com/cirospaciari/socketify.py.git@main#socketify
2022-05-29 00:00:21 +00:00
```
2022-05-24 19:37:16 +00:00
```bash
2022-05-29 00:00:21 +00:00
pip install -r ./requirements.txt
#or specify PyPy3
pypy3 -m pip install -r ./requirements.txt
2022-05-24 19:37:16 +00:00
```
2022-05-25 14:01:56 +00:00
2022-11-08 11:34:26 +00:00
## Examples
Hello world app
```python
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()
```
2022-11-08 11:25:54 +00:00
SSL version sample
2022-05-25 14:01:56 +00:00
``` python
2022-05-28 13:47:26 +00:00
from socketify import App, AppOptions
2022-05-25 14:01:56 +00:00
app = App(AppOptions(key_file_name="./misc/key.pem", cert_file_name="./misc/cert.pem", passphrase="1234"))
2022-05-28 13:47:26 +00:00
app.get("/", lambda res, req: res.end("Hello World socketify from Python!"))
2022-05-28 19:59:08 +00:00
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
2022-05-25 14:01:56 +00:00
app.run()
2022-05-28 20:04:35 +00:00
```
2022-11-08 11:34:26 +00:00
We have more than 20 examples [click here](https://github.com/cirospaciari/socketify.py/tree/main/examples) for more
## Build local from source
2022-05-28 20:04:35 +00:00
```bash
#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 ../../../
2022-05-29 00:00:21 +00:00
#install local pip
2022-11-04 23:08:20 +00:00
pypy3 -m pip install .
2022-05-29 00:00:21 +00:00
#install in editable mode
pypy3 -m pip install -e .
2022-05-28 20:04:35 +00:00
#if you want to remove
pypy3 -m pip uninstall socketify
2022-10-11 12:33:55 +00:00
```
2022-11-08 14:25:29 +00:00
## Commercially supported
2022-11-08 14:29:53 +00:00
I'm a Brazilian consulting & contracting company dealing with anything related with [socketify.py](https://github.com/cirospaciari/socketify.py) and [socketify.rb](https://github.com/cirospaciari/socketify.rb)
2022-11-08 14:25:29 +00:00
2022-11-08 14:31:56 +00:00
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.
2022-11-08 14:25:29 +00:00
Special thank's to [uNetworking AB](https://github.com/uNetworking) to develop [uWebSockets](https://github.com/uNetworking/uWebSockets), [uSockets](https://github.com/uNetworking/uSockets) and allow us to bring this features and performance to Python and PyPy