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
- Support all subscription configuration available in stan.py
- Healthcheck available using HTTP GET request to monitor the applications
- (TODO) Metrics available using HTTP GET requests to monitor subsriptions status
- All of FastAPI features
Quick start
- Install the package from pypi:
pip install faststan
- Create your first subscriber. Create a file named
app.pyand write the following lines:
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
- Or if you are in a jupyter notebook environment, start the subscriptions:
await app.start()
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
faststan-0.1.3.tar.gz
(5.1 kB
view details)
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.3.tar.gz.
File metadata
- Download URL: faststan-0.1.3.tar.gz
- Upload date:
- Size: 5.1 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 |
f42476d5c44f8c2df03f3cfa4e77ee79615064fc2aef0ae88f1593fbad7ffbec
|
|
| MD5 |
8b02827e44e48a83a1f4cea6a48a3784
|
|
| BLAKE2b-256 |
d4bcf16f35e956b4d823656b71a782517bd787c4ca58317f3444119e5f138dc9
|
File details
Details for the file faststan-0.1.3-py3-none-any.whl.
File metadata
- Download URL: faststan-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.9 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 |
f30bdc8788ac2d37458045fb389f89d185ef6845ad5062e203e365810e8430b4
|
|
| MD5 |
0d2a96d92546f03c44c04d42fc0a332e
|
|
| BLAKE2b-256 |
e600d33d10add8918497352c56cc89d2d36e1931920f3ccb5119c2fd3dd4db4e
|