2022-05-28 13:47:26 +00:00
|
|
|
# socketify.py
|
2022-05-24 19:37:16 +00:00
|
|
|
Fast WebSocket and Http/Https server using CFFI with C API from [uNetworking/uWebSockets](https://github.com/uNetworking/uWebSockets)
|
|
|
|
|
|
|
|
> This project will adapt the full capi from uNetworking/uWebSockets but for now it's just this.
|
|
|
|
|
|
|
|
### Overly simple hello world app
|
|
|
|
```python
|
2022-05-28 13:47:26 +00:00
|
|
|
from socketify import App
|
2022-05-24 19:37:16 +00:00
|
|
|
|
2022-05-25 14:01:56 +00:00
|
|
|
app = App()
|
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-24 19:37:16 +00:00
|
|
|
app.run()
|
|
|
|
```
|
|
|
|
|
2022-05-28 20:04:35 +00:00
|
|
|
### pip install
|
2022-05-24 19:37:16 +00:00
|
|
|
|
|
|
|
```bash
|
2022-05-28 22:49:16 +00:00
|
|
|
pip install git+https://github.com/cirospaciari/socketify.py.git --global-option=build_ext
|
2022-05-28 20:04:35 +00:00
|
|
|
#or specify PyPy3
|
2022-05-28 22:49:16 +00:00
|
|
|
pypy3 -m pip install git+https://github.com/cirospaciari/socketify.py.git --global-option=build_ext
|
2022-05-24 19:37:16 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Run
|
|
|
|
```bash
|
|
|
|
pypy3 ./hello_world.py
|
|
|
|
```
|
2022-05-25 14:01:56 +00:00
|
|
|
|
|
|
|
### SSL version sample
|
|
|
|
``` 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
|
|
|
```
|
|
|
|
|
|
|
|
### Build local from source
|
|
|
|
```bash
|
|
|
|
#clone and update submodules
|
|
|
|
git clone https://github.com/cirospaciari/socketify.py.git
|
|
|
|
cd ./socketify.py
|
|
|
|
git submodule update --init --recursive --remote
|
|
|
|
#install build with pip
|
|
|
|
pypy3 -m pip install --upgrade build
|
|
|
|
#build and install
|
|
|
|
pypy3 -m build
|
2022-05-28 22:49:16 +00:00
|
|
|
pypy3 -m pip install . --no-cache-dir --global-option=build_ext
|
2022-05-28 20:04:35 +00:00
|
|
|
#if you want to remove
|
|
|
|
pypy3 -m pip uninstall socketify
|
2022-05-25 14:01:56 +00:00
|
|
|
```
|