A micro web framework for AWS Lambda.
Project description
Vial
A micro web framework for AWS Lambda.
Installation
To add vial to your project, run the following command:
pip install pyvial
Usage
Entry Point
The main entry point of the application is always the Vial#__call__ function. When deploying to AWS Lambda,
the Lambda handler should point to the Vial object in whichever file it's defined in. As an example:
from vial.app import Vial
app = Vial()
If this code snippet is defined in an app.py file, the handler would be app.app.
Basic API
from typing import Mapping
from vial.app import Vial
app = Vial()
@app.get("/hello-world")
def hello_world() -> Mapping[str, str]:
return {"hello": "world"}
Path Parameters
You can define path parameters like this:
@app.get("/users/{user_id}")
def get_user(user_id: str) -> User:
return user_service.get(user_id)
Vial supports some path parameter parsing as part of the invocation process. For example when using a UUID as a path parameter, Vial can convert it from a string to a UUID automatically:
from uuid import UUID
@app.get("/users/{user_id:uuid}")
def get_user(user_id: UUID) -> User:
return user_service.get(user_id)
The following parsers are supported by default:
| Parser | Type |
|---|---|
str |
str |
bool |
bool |
int |
int |
float |
float |
decimal |
decimal.Decimal |
uuid |
uuid.UUID |
You can register your own parser like this:
@app.parser("list")
def list_parser(value: str) -> List[str]:
return [value]
@app.get("/users/{user_id:list}")
def get_user(user_ids: List[str]) -> User:
return user_service.get(user_id)
As parsers are bound directly to the registered route function, they have to be defined before the route function that uses one is registered.
Json Encoding
You can customize how Vial serializes / deserializes JSON objects by passing a custom encoder. The below
example shows how to substitute the native JSON module with another library like simplejson:
import simplejson
from vial.app import Vial, Json
class SimpleJson(Json):
@staticmethod
def dumps(value: Any) -> str:
return simplejson.dumps(value)
@staticmethod
def loads(value: str) -> Any:
return simplejson.loads(value)
class JsonVial:
json_class = SimpleJson
app = SimpleJsonVial()
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 pyvial-0.2.0.tar.gz.
File metadata
- Download URL: pyvial-0.2.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.2 Darwin/20.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73de1eff7f1f405ba9e65201bd7c1f31c02008d69408bda39c97aacca6d8104b
|
|
| MD5 |
cafcf35dbb21ee8179aeebd520c02d10
|
|
| BLAKE2b-256 |
b9f2454ed47ebfa955f1e5195e932f1265509689990a46951f03a3b0215b9156
|
File details
Details for the file pyvial-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pyvial-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.2 Darwin/20.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
796b0f5acb07f02812c0e932965da40c71e43774a4aa1286cbf1c2ae7ed0518c
|
|
| MD5 |
e482a8b104ec3d6997e695e7bbf4fbf3
|
|
| BLAKE2b-256 |
41e264af285ac2432150fd81d04907a89db460743422ca06c75e678ee70dd9d6
|