Tool for creating crud routes from pony database object
Project description
Fast Pony CRUD
A tool for easily adding database CRUD routes using pony orm and FastAPI. This package works with database definitions using the common pony orm data types, but it still needs to be tested on all of them.
Installation
using pip:
pip install fast-pony-crud
Usage:
Define your database. You can do this in code, or you can use the Pony ORM online editor. You will end up with a file that looks something like this. save it as "db.py".
from datetime import datetime
from pony.orm import *
db = Database()
class Device(db.Entity):
name = PrimaryKey(str)
data_channels = Set('DataChannel')
class ChannelEntry(db.Entity):
id = PrimaryKey(int, auto=True)
time = Required(datetime,default=lambda:datetime.utcnow())
numeric_value = Optional(float)
metadata = Optional(Json)
data_channel = Required('DataChannel')
class DataChannel(db.Entity):
id = PrimaryKey(int, auto=True)
name = Required(str)
device = Required(Device)
device_time_entrys = Set(ChannelEntry)
data_type = Required('DataType')
class DataType(db.Entity):
id = PrimaryKey(str)
data_channels = Set(DataChannel)
metadata_config = Optional(Json)
Set up your API. Here we follow steps similar to the ones outlined in the FastAPI guide. The example uses an sqlite database for simplicity, but pony can connect to a variety of database backends. Save this file as "api.py".
from fastapi import FastAPI
from db import db # imports our database definition
from fast_pony_crud import create_crud_routes
import uvicorn
app = FastAPI()
# Connect to database
db.bind(provider='sqlite', filename='database.sqlite', create_db=True)
db.generate_mapping(create_tables=True)
# this is where the magic happens:
create_crud_routes(
db,
app,
prefix="/db", # prefix for all datbase crud routes
api_key="YOUR_SECRET_KEY") # api key for authentification sent on request headers
Launch the app by typing the following in your command shell:
uvicorn api:app --reload
Now you can view your api docs by going to http://127.0.0.1:8000/docs
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
File details
Details for the file fast-pony-crud-0.0.8.tar.gz
.
File metadata
- Download URL: fast-pony-crud-0.0.8.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b6beaa1a259fc7e06b039c78ad11952f0b26361bcdb955df1661a72aceae624 |
|
MD5 | 33f297987547ffa8ec41aaf0fcd3b0d9 |
|
BLAKE2b-256 | eaf269e2d4b61a5d315c6c90d9d87d57e7ccdcbcd07ce3c2419553a344ce82db |
File details
Details for the file fast_pony_crud-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: fast_pony_crud-0.0.8-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92f24e93f4adee9a4942054c31732b7d999df631e9386febd8ecc4056e686e93 |
|
MD5 | 1de6fb7611f596b16b5450a5a720a398 |
|
BLAKE2b-256 | f5d5c9861ba0710c76975dad13d0faa3816dfea017d566a21f68e02c467867f2 |