Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/woodruffw/cazart
Flask + schema = cazart!
https://github.com/woodruffw/cazart
flask jsonschema validation
Last synced: about 1 month ago
JSON representation
Flask + schema = cazart!
- Host: GitHub
- URL: https://github.com/woodruffw/cazart
- Owner: woodruffw
- License: other
- Created: 2019-08-18T12:34:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-28T00:09:33.000Z (over 3 years ago)
- Last Synced: 2024-10-15T22:10:43.361Z (about 1 month ago)
- Topics: flask, jsonschema, validation
- Language: Python
- Homepage: https://pypi.org/project/cazart/
- Size: 21.5 KB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
cazart
======![license](https://raster.shields.io/badge/license-MIT%20with%20restrictions-green.png)
[![Build Status](https://img.shields.io/github/workflow/status/woodruffw/cazart/CI/master)](https://github.com/woodruffw/cazart/actions?query=workflow%3ACI)*Flask + schema = cazart!*
**cazart** is a small helper for writing schematized JSON endpoints with Flask. It rolls
[schema](https://github.com/keleshev/schema) into Flask's `route` decorator, allowing
for one-shot route and schema specification.## Installation
**cazart** requires Python 3.6 or newer.
```bash
pip3 install cazart
```## Usage
To use **cazart**, just swap your `Flask` instance out for a `Cazart` one:
```python
from cazart import Cazartapp = Cazart(__name__)
```You can access all of Flask's baseline functionality (including non-validated routes)
via `app.flask`.Then, use `app.route` to specify a combination route and schema:
```python
from cazart import Cazart
from schema import Schema, Orapp = Cazart(__name__)
@app.route("/cazart", schema=Schema({"name": Or("alice", "bob", "mary")}))
def cazart(res):
print(f"my verified payload is {res}!")
return ("ok", 200)
```See the [examples](./example) for full usage examples, including custom error handling
and dispatching to different schemas on a route based on HTTP method.