Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vladisa88/fastapi-ormar-utilities
Small package for making views in FastAPI cleaner
https://github.com/vladisa88/fastapi-ormar-utilities
fastapi orm ormar python rest
Last synced: 3 months ago
JSON representation
Small package for making views in FastAPI cleaner
- Host: GitHub
- URL: https://github.com/vladisa88/fastapi-ormar-utilities
- Owner: vladisa88
- Created: 2021-03-01T11:01:56.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-30T08:25:12.000Z (almost 4 years ago)
- Last Synced: 2024-10-09T11:24:37.519Z (3 months ago)
- Topics: fastapi, orm, ormar, python, rest
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FASTAPI-ORMAR-UTILITIES
![](https://www.code-inspector.com/project/19657/score/svg)
## Small package for better interaction with Ormar ORM.### This package makes your views cleaner
### Features:
* Fully async
* Compatible with FastAPI
* In my opinion Ormar is the best ORM for FastAPI
* Support `select_related()` method
* Handle `Not found` exceptions### Install with pip
```
pip install fastapi-ormar-utilities[all]
```### Example usage:
```pythonfrom fastapi import APIRouter, Depends
from fastapi_ormar_utilities import Basefrom .models import Item # import Ormar model
from .schemas import ItemCreate # import Pydantic modelrouter = APIRouter()
class ItemService(Base):
model = Item@router.get('/')
async def get_items(
service: ItemService = Depends()
):
return await service.fetch_all()@router.get('/')
async def get_items_with_related(
service: ItemService = Depends()
):
# if you want to add related field to the query
return await service.fetch_all(related_field='some_field')@router.post('/')
async def create_item(
item_data: ItemCreate,
service: ItemService = Depends()
):
return await service.create(item_data)
```