Build data streaming pipelines using faststan
Project description
FastSTAN
Easily deploy NATS Streaming subscribers using Python.
Features
-
Define subscribers using sync and async python functions
-
Automatic data parsing and validation using type annotations and pydantic
-
Support custom validation using any function
-
Allow several subscribers on same channel
-
Healthcheck available using HTTP GET request to monitor the applications
-
(TODO) Metrics available using HTTP GET requests
-
All of FastAPI features
Quick start
- Install the package from pypi:
pip install faststan
- Create your first subscriber:
from faststan.faststan import FastSTAN
app = FastSTAN()
@app.subscribe("demo")
def on_event(message: str):
print(f"INFO :: Received new message: {message}")
- Start your subscriber:
uvicorn app:app
Advanced features
Using error callbacks
from faststan.faststan import FastSTAN
app = FastSTAN()
def handle_error(error):
print("ERROR: {error}")
@app.subscribe("demo", error_cb=handle_error)
def on_event(message: str):
print(f"INFO :: Received new message: {message}")
Using pydantic models
You can use pydantic models in order to automatically parse incoming messages:
from pydantic import BaseModel
from faststan.faststan import FastSTAN
class Event(BaseModel):
timestamp: int
temperature: float
humidity: float
app = FastSTAN()
@app.subscribe("event")
def on_event(event):
msg = f"INFO :: {event.timestamp} :: Temperature: {event.temperature} | Humidity: {event.humidity}"
print(msg)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file faststan-0.1.1.tar.gz.
File metadata
- Download URL: faststan-0.1.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.7.5 Linux/4.4.0-17763-Microsoft
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e33eccf2e4688f0ac7657cc1011d4d8b9c2f98bd58fc2f66d7bc9ce1e0c25dce
|
|
| MD5 |
390aecbfceb5a95a0d978a00ef208f6f
|
|
| BLAKE2b-256 |
fa74dc8288952d2f2f8d7041415a684ecc8160bf989aba50c3717903aad507a8
|
File details
Details for the file faststan-0.1.1-py3-none-any.whl.
File metadata
- Download URL: faststan-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.7.5 Linux/4.4.0-17763-Microsoft
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14d5c163cd8ee96a35d9fd29862d866bfb7537ad1bda551dea35629b8e5e3e27
|
|
| MD5 |
8b320b9edc8885bb7d6cf7500afd03ed
|
|
| BLAKE2b-256 |
e8b5dec2d129cc5158a42d9f08b04a436a8539a64f959810ae1123472aaff3e6
|