Skip to main content

A simple API Websocket server to easily parse JSON

Project description

Description

FastWAPI is a simple lightweight Websocket framework based on Starlette, which provide easy-to-use Python decorator to parse JSON incoming message.

It's in the same spirit as FastAPI, where each decorator map to an HTTP path. But here, each decorator map to a Pydantic object, and each object map to a function.

Installation

pip install fastwapi

Disclaimer

  • The module is available, but far from finished & polished, please do not use it in production.

Roadmap

  • Add authent middleware
  • Add background job to asynchrounosly send JSON to the client

Usage

See example/main.py for complete code.

Getting started in three steps :

Instanciates the framework and declare the Websocket HTTP endpoint.

import uvicorn
from fastwapi import FastWAPI, WebSocket
from pydantic import BaseModel

app = FastWAPI(endpoint="/ws")

Define Pyndantic model, for incoming and outgoing messages.

class CM(BaseModel):
    counter: int

class SD(BaseModel):
    name: str

Map each Pydantic model to your function.

@app.parse(CM)
async def parse_CM(websocket: WebSocket, data: CM):
    print("RECEIVED CM : ", data)
    await websocket.send_json(data.dict())

@app.parse(SD)
async def parse_SD(websocket: WebSocket, data: CM):
    print("RECEIVED SD : ", data)
    await websocket.send_json(data.dict())

Launch your app

Either through command line "uvicorn main:app" or directly inside the python file :

if __name__ == "__main__":
    uvicorn.run("main:app", port=5000, log_level="info")

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

fastwapi-0.1.3.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

fastwapi-0.1.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file fastwapi-0.1.3.tar.gz.

File metadata

  • Download URL: fastwapi-0.1.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for fastwapi-0.1.3.tar.gz
Algorithm Hash digest
SHA256 69d206f98dc65be729ab96d11cfc92565a815b38f8edc2a1c362804dd83590e7
MD5 a2a44e5a5529316a2059b3cc423caa70
BLAKE2b-256 5dacea1bb40ad2fc348039e7c0d384436b57d54b54c9c53db2d361767e1682b3

See more details on using hashes here.

File details

Details for the file fastwapi-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: fastwapi-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for fastwapi-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 762fee5b90cda9b01688bb2e3f9043d13c20a93508a327a5dc9d06a5e94875f3
MD5 c00d0899ce25495d90978cf05dbf4036
BLAKE2b-256 0cad8726495ebe671599e95ee5ed1aac31bc402570e2176ed4f22cdf246b491a

See more details on using hashes here.

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