Skip to content

Implementation RealWorld project. Fastapi, pydantic, sqlalchemy, pytest, asyncio, aioredis, docker-compose.

License

Notifications You must be signed in to change notification settings

nightriddler/fastapi_realworld

Repository files navigation

FastAPI Realworld

logo

Styles Tests codecov Code style: black license MIT

FastAPI SQLAlchemy Pydantic

Implementation for RealWorld project using FastAPI and SQLAlchemy.

Also:

fastapi
pydantic
sqlalchemy
alembic
asyncpg
asyncio
aioredis
pytest
httpx

Redis for cache favorite articles and count favorite articles.

Deployment in Docker

  1. Clone repository
git clone https://github.com/nightriddler/fastapi_realworld.git
  1. In the root folder create a file .env with environment variables (or rename the file .env.example to .env)::
SECRET=secret-key
DATABASE_URL=postgresql+asyncpg2://postgres:postgres@db/postgres
REDIS_URL=redis://redis:6379

You can generate your SECRET with the command (from the root):

echo SECRET=$(openssl rand -hex 32) >> .env
  1. In the same folder, run docker-compose with the command
docker-compose up
  1. The project is available at
http://127.0.0.1:8000/docs/

The pgAdmin panel is available:

http://127.0.0.1:5050/

Testing in Docker

Run the migration to test it:

docker-compose exec web alembic upgrade head

And then, run the tests:

docker-compose exec web python -m pytest

Deployment local

  1. Clone repository
git clone https://github.com/nightriddler/fastapi_realworld.git
  1. Create a virtual environment and activate it:
python -m venv venv
source venv/Scripts/activate 
  1. Install go to the backend folder and install the dependencies:
cd backend/
pip install -r requirements.txt
  1. Create a .env (you can use .env.example), with your SECRET and DATABASE_URL in the same backend folder.

  2. Run the migrations:

alembic head upgrade
  1. Run the application:
uvicorn main:app --reload
  1. The app will be available at:
http://127.0.0.1:8000/docs
  1. Running tests:
python -m pytest

Documentation

The documentation /docs/openapi.yml can be seen at https://editor.swagger.io/ and also when you start the project at http://127.0.0.1:8000/docs/.

Contact the author

LinkedIn

Telegram

Portfolio

About

Implementation RealWorld project. Fastapi, pydantic, sqlalchemy, pytest, asyncio, aioredis, docker-compose.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages