Async web framework on top of fastapi and orm
Project description
joey
Async web framework on top of fastapi and orm
How to start
Let's create demo project
$ mkdir demo-project
$ cd demo-project
$ pipenv install joey
$ pipenv shell
$ joey init
Joey will create the following project structure
.
├── alembic.ini
├── asgi.py
├── migrations
│ ├── env.py
│ ├── script.py.mako
│ └── versions
└── settings
├── common.py
├── common.yml
├── development.py
└── __init__.py
Let's add the application to the given project structure
$ joey add hello
# or with autoregister parameter
$ joey add -a hello
Joey will add the following files in a separate folder
.
└── hello
├── __init__.py
├── models.py
└── routes.py
If you use -a
flag then joey automatic register your app and route in project settings file
APPLICATIONS:
- hello
ROUTES:
hello:
prefix: /hello
tags:
- hello
otherwise manually edit settings/common.yml
file.
Now implement model in file hello/models.py
class Item(Model):
id = orm.Integer(primary_key=True)
text = orm.Text()
Implement a simple route in hello/routes.py
, than can access to database
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from hello.models import Item as ItemDB
class Item(BaseModel):
text: str
router = APIRouter()
@router.post('/{id}', response_model=Item)
async def item(id: int) -> Item:
try:
return await ItemDB.objects.get(id=id)
except ItemDB.DoesNotExist:
raise HTTPException(status_code=404, detail='Item not found')
Next step - create a database, then migrate it and add a couple of elements
$ joey revise 'init database'
$ joey migrate
$ sqlite3 db.sqlite "insert into items (text) values ('hello'), ('joe here');"
Everything is ready, now you can start with uvicorn
$ joey run
# or
$ uvicorn asgi:app --reload
And request data with Swagger UI by http://localhost:8000/docs
.
Project details
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 joey-0.4.0.tar.gz
.
File metadata
- Download URL: joey-0.4.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dd756e6ecfe542f6c3b3536cabaa8832c449fd22c3cc3013c6ce070959a381d |
|
MD5 | 2e86c3918cd54dbb5e8b9ece62048211 |
|
BLAKE2b-256 | 3b9d960d6b29769088f0faf2566f62bd91ca8ec1bfcd5377af8f5e3c878d9494 |
File details
Details for the file joey-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: joey-0.4.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74a1b49357f2346d7739a229e3d14812936c81a4beb99fc9c26dcbe55936066b |
|
MD5 | 95446d7a16f44df962618bcc00f123d1 |
|
BLAKE2b-256 | 50e623ba65ef7ac326f78fdb954a45a6d2ed7d65a0119197f4df74277e5dab4e |