All Projects → wedwardbeck → lrnfast

wedwardbeck / lrnfast

Licence: MIT license
FastAPI Notes Example using databases and postgresql

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects
PLpgSQL
1095 projects
Dockerfile
14818 projects
shell
77523 projects
Mako
254 projects

Projects that are alternatives of or similar to lrnfast

Apollo
A basic Application with multiple functionalities built with FastAPI aim to help Users Buy New Items Provided using PaypalAPI 🚀
Stars: ✭ 22 (+83.33%)
Mutual labels:  fastapi, fastapi-crud
freddie
DRF-like declarative viewsets for FastAPI
Stars: ✭ 49 (+308.33%)
Mutual labels:  fastapi, fastapi-crud
fastapi-pydiator
Python clean architecture and usecase implementation with fastapi and pydiator-core
Stars: ✭ 58 (+383.33%)
Mutual labels:  fastapi, fastapi-crud
postile
Project migrated to: https://gitlab.com/Oslandia/postile
Stars: ✭ 67 (+458.33%)
Mutual labels:  asyncpg
sanic-url-shortener
Example of how to use Sanic and asyncpg (PostgreSQL)
Stars: ✭ 16 (+33.33%)
Mutual labels:  asyncpg
yappa
Serverless deploy of python web-apps @yandexcloud
Stars: ✭ 57 (+375%)
Mutual labels:  fastapi
fastAPI-aiohttp-example
How to use and test fastAPI with an aiohttp client
Stars: ✭ 69 (+475%)
Mutual labels:  fastapi
30 Days Of Python
Learn Python for the next 30 (or so) Days.
Stars: ✭ 1,748 (+14466.67%)
Mutual labels:  fastapi
restish
Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
Stars: ✭ 453 (+3675%)
Mutual labels:  fastapi
blog-fastapi-vuejs
Simple project that I write using fastapi, motor, and umongo for the backend. VueJS on the frontend
Stars: ✭ 76 (+533.33%)
Mutual labels:  fastapi
FRDP
Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⭐
Stars: ✭ 55 (+358.33%)
Mutual labels:  fastapi
Gino
GINO Is Not ORM - a Python asyncio ORM on SQLAlchemy core.
Stars: ✭ 2,299 (+19058.33%)
Mutual labels:  asyncpg
fastapi-admin
A fast admin dashboard based on FastAPI and TortoiseORM with tabler ui, inspired by Django admin
Stars: ✭ 1,765 (+14608.33%)
Mutual labels:  fastapi
dvhb-hybrid
A package to mix django and asyncio in one application
Stars: ✭ 45 (+275%)
Mutual labels:  asyncpg
starlette-context
Middleware for Starlette that allows you to store and access the context data of a request. Can be used with logging so logs automatically use request headers such as x-request-id or x-correlation-id.
Stars: ✭ 320 (+2566.67%)
Mutual labels:  fastapi
postmodel
ORM library for Python 3.6+, asyncio. Provides Django ORM like API.
Stars: ✭ 15 (+25%)
Mutual labels:  asyncpg
FastAPI Tortoise template
FastAPI - Tortoise ORM - Celery - Docker template
Stars: ✭ 144 (+1100%)
Mutual labels:  fastapi
ms-fastapi-template
This project was built as a result of a deepening of the studies discussed on the blog farlley.com with a greater focus on Domain Driven Design (DDD) architecture. In this work you will find a simple template for creating microservices, as well as a use case (which will still be implemented according to the Roadmap found in this same document) a…
Stars: ✭ 31 (+158.33%)
Mutual labels:  fastapi
fastapi-debug-toolbar
A debug toolbar for FastAPI.
Stars: ✭ 90 (+650%)
Mutual labels:  fastapi
fastdash
FastDash = FastAPI + DashBoard.
Stars: ✭ 23 (+91.67%)
Mutual labels:  fastapi

FastAPI CRUD using Async, Alembic & Postgresql

Version

Example Async CRUD API using FastAPI

This repository is the result of wading through how to use async CRUD operations using the backend core from the excellent generator template by Sebastián Ramírez, Full Stack FastAPI and PostgreSQL - Base Project Generator.

In reviewing the FastAPI docs, the encode/databases docs on queries, and the gitter channels, there seemed to be only the basic information on using databases with SQL Alchemy and data table definitions that would not work well with Alembic autogenerate - as least in my case using the generator template. This repository is the working result of my tests and learning to use FastAPU with async, asycnpg, databases, and Alembic autogenerated migrations with declarative base model. Hopefully it will be useful to others looking for some examples of using databases, asyncpg and Alembic with FastAPI.

Updates

Version 0.3.0 Dockerfiles & Docker-Compose ready containing two services, PSQL & APP.

  • PSQL - Postgresql 12-alpine image.
  • APP - ClearLinux/Python3.8 image with custom build.
  • Auto Migrations - Migrations including creation of stored procedures in APP image.
  • .env Sample - Change to .env and provide desired values.

Details

  • Uses version 0.4.0 of the Fullstack generator: before current changes in structure of the project were made.
  • encode/databases: To simplify managing connections, pooling, etc.
  • asyncpg with Posgresql: Built using a Postgresql 12 database, but can be altered to use SQLite.
  • Alembic: Using autogenerate to create migrations.
  • Version 0.1.0: Uses raw SQL in CRUD functions. See tag v0.1.0.
  • Version 0.2.0: Uses functions (reads) and procedures (write). Procedures require Posgresql Version 11 or higher.
  • Version 0.3.0: Uses Docker-Compose to spin up services and run migrations.

Critical Notes

  • PyCharm (or other IDE) may complain about the PSQL Procedures using "CALL" - I just injected SQL lanuage on the query text to eliminate the errors.
  • Some CRUD functions utilize databases.fetch_val() and require using the latest master branch of databases from the repo. The version on PyPi is not correct, and is missing the April 30 commit with the required changes to use this. See this commit.
  • Clone the [encode/databases] repo into the "backend" folder before running docker-compose up --build.
  • If not patching or using the current repo from PyPi (says 0.3.2 but really is <=0.3.1)- databases.fetch_one() needs to be used or the get by ID and create routes will fail.

Installation Instructions

  • Clone the repo.
  • Clone the [encode/databases] repo into the "backend" folder.
  • Change the sample.env file to .env and enter your preferred values.
  • Run Docker Compose (with -d for detached, or omit to run in foreground):
$ docker-compose up --build
  • In the browser, go to localhost:8000/docs
  • Login using the super user email and password supplied in the .env file.
  • Test routes.
  • When done:
$ docker-compose down

You can rerun the docker-compose up and the datbase data will be persistent.

You can also remove the named volume where the database data resides by adding the -v flag:

$ docker-compoise down -v

To Do

Tests, deployment via docker, and other changes to come, time permitting. Want to see these sooner - see below in Contributing.

Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/YourFeature)
  3. Commit your Changes (git commit -m 'Add My Feature')
  4. Push to the Branch (git push origin feature/YourFeature)
  5. Open a Pull Request

Contact

Edward Beck

License

This project is licensed under the terms of the MIT license.


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].