lite additions to tornado.
Project description
Gust
Gust is a wrapper of tornado. It allows for a hello world such as:
from blueshed.gust import Gust, web
@web.get('/(.*)')
def get(request):
"""just a get"""
return 'hello, world'
def main():
"""seperate construction from run"""
Gust().run()
if __name__ == '__main__':
main()
Similarly, you can write:
@web.ws_json_rpc('/websocket')
def add(a:float, b:float) -> float:
"""simple addition"""
return a + b
And use a javascript websocket client to call the function:
const ws = new WebSocket("ws://localhost:8080/websocket");
ws.onopen = function () {
ws.send(
JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "add",
params: { a: 2.0, b: 2.0 }, // or [2.0, 2.0]
}),
);
};
ws.onmessage = function (evt) {
const pre = document.createElement("pre");
pre.textContent = evt.data;
document.body.appendChild(pre);
};
Direct PostgreSQL Function Calling
Gust also supports calling PostgreSQL stored functions directly via WebSocket JSON-RPC:
from blueshed.gust import Gust, web, PostgresRPC
from psycopg import AsyncConnection
async def main():
conn = await AsyncConnection.connect("postgresql://user:pass@localhost/mydb")
pg_rpc = PostgresRPC(conn)
web.ws_json_rpc('/api', handler=pg_rpc)
Gust(port=8080).run()
Call any PostgreSQL function using the same JSON-RPC protocol shown above. An authenticated variant (AuthPostgresRPC) is available for automatic user injection. See samples/postgres_rpc_demo/ for complete examples.
There are simple sample apps in src/tests.
Project details
Release history Release notifications | RSS feed
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 blueshed_gust-0.0.26.tar.gz.
File metadata
- Download URL: blueshed_gust-0.0.26.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0349227b6f9e0772d5f4782ed8b402033ed6f6f75e2f25965135106fa8b4686
|
|
| MD5 |
34b8ac8db7470b8ab068b6c551c15f9c
|
|
| BLAKE2b-256 |
230d9a121008b2e6d1eb1af08a48fe4519b462bdad4d786ca7260a82c521f29e
|
File details
Details for the file blueshed_gust-0.0.26-py3-none-any.whl.
File metadata
- Download URL: blueshed_gust-0.0.26-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1107d9bf1e4af0a2c35486a53d9f25a6f660ddcd41a1fd3b5e611e38a9a1c49d
|
|
| MD5 |
e6b83fe23107d7aae2b12cf58a41c4db
|
|
| BLAKE2b-256 |
1183c571a8d9c126c0d1dfccb34e3db589daf25e950c0dfcfc710fff04900f8c
|