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.
- Clone repository
git clone https://github.com/nightriddler/fastapi_realworld.git
- 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
- In the same folder, run docker-compose with the command
docker-compose up
- The project is available at
http://127.0.0.1:8000/docs/
The pgAdmin panel is available:
http://127.0.0.1:5050/
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
- Clone repository
git clone https://github.com/nightriddler/fastapi_realworld.git
- Create a virtual environment and activate it:
python -m venv venv
source venv/Scripts/activate
- Install go to the backend folder and install the dependencies:
cd backend/
pip install -r requirements.txt
-
Create a
.env
(you can use.env.example
), with yourSECRET
andDATABASE_URL
in the same backend folder. -
Run the migrations:
alembic head upgrade
- Run the application:
uvicorn main:app --reload
- The app will be available at:
http://127.0.0.1:8000/docs
- Running tests:
python -m pytest
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/
.