{"id":13424994,"url":"https://github.com/nsidnev/fastapi-realworld-example-app","last_synced_at":"2025-10-02T15:30:51.458Z","repository":{"id":37382279,"uuid":"168056889","full_name":"nsidnev/fastapi-realworld-example-app","owner":"nsidnev","description":"Backend logic implementation for https://github.com/gothinkster/realworld with awesome FastAPI","archived":true,"fork":false,"pushed_at":"2022-08-21T02:23:41.000Z","size":1029,"stargazers_count":2798,"open_issues_count":0,"forks_count":628,"subscribers_count":42,"default_branch":"master","last_synced_at":"2024-09-25T01:35:24.495Z","etag":null,"topics":["async","docker","docker-compose","fastapi","github-actions","postgresql","python","python3","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nsidnev.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-28T23:47:19.000Z","updated_at":"2024-09-23T05:51:22.000Z","dependencies_parsed_at":"2022-07-11T03:00:50.478Z","dependency_job_id":null,"html_url":"https://github.com/nsidnev/fastapi-realworld-example-app","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsidnev%2Ffastapi-realworld-example-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsidnev%2Ffastapi-realworld-example-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsidnev%2Ffastapi-realworld-example-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsidnev%2Ffastapi-realworld-example-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsidnev","download_url":"https://codeload.github.com/nsidnev/fastapi-realworld-example-app/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219875832,"owners_count":16554706,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","docker","docker-compose","fastapi","github-actions","postgresql","python","python3","tutorial"],"created_at":"2024-07-31T00:01:01.655Z","updated_at":"2025-10-02T15:30:46.128Z","avatar_url":"https://github.com/nsidnev.png","language":"Python","funding_links":[],"categories":["Projects","Python","Examples","HarmonyOS"],"sub_categories":["Open Source Projects","Windows Manager"],"readme":".. image:: ./.github/assets/logo.png\n\n|\n\n.. image:: https://github.com/nsidnev/fastapi-realworld-example-app/workflows/API%20spec/badge.svg\n   :target: https://github.com/nsidnev/fastapi-realworld-example-app\n\n.. image:: https://github.com/nsidnev/fastapi-realworld-example-app/workflows/Tests/badge.svg\n   :target: https://github.com/nsidnev/fastapi-realworld-example-app\n\n.. image:: https://github.com/nsidnev/fastapi-realworld-example-app/workflows/Styles/badge.svg\n   :target: https://github.com/nsidnev/fastapi-realworld-example-app\n\n.. image:: https://codecov.io/gh/nsidnev/fastapi-realworld-example-app/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/nsidnev/fastapi-realworld-example-app\n\n.. image:: https://img.shields.io/github/license/Naereen/StrapDown.js.svg\n   :target: https://github.com/nsidnev/fastapi-realworld-example-app/blob/master/LICENSE\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :target: https://github.com/ambv/black\n\n.. image:: https://img.shields.io/badge/style-wemake-000000.svg\n   :target: https://github.com/wemake-services/wemake-python-styleguide\n\n----------\n\n**NOTE**: This repository is not actively maintained because this example is quite complete and does its primary goal - passing Conduit testsuite.\n\nMore modern and relevant examples can be found in other repositories with ``fastapi`` tag on GitHub.\n\nQuickstart\n----------\n\nFirst, run ``PostgreSQL``, set environment variables and create database. For example using ``docker``: ::\n\n    export POSTGRES_DB=rwdb POSTGRES_PORT=5432 POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres\n    docker run --name pgdb --rm -e POSTGRES_USER=\"$POSTGRES_USER\" -e POSTGRES_PASSWORD=\"$POSTGRES_PASSWORD\" -e POSTGRES_DB=\"$POSTGRES_DB\" postgres\n    export POSTGRES_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pgdb)\n    createdb --host=$POSTGRES_HOST --port=$POSTGRES_PORT --username=$POSTGRES_USER $POSTGRES_DB\n\nThen run the following commands to bootstrap your environment with ``poetry``: ::\n\n    git clone https://github.com/nsidnev/fastapi-realworld-example-app\n    cd fastapi-realworld-example-app\n    poetry install\n    poetry shell\n\nThen create ``.env`` file (or rename and modify ``.env.example``) in project root and set environment variables for application: ::\n\n    touch .env\n    echo APP_ENV=dev \u003e\u003e .env\n    echo DATABASE_URL=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB \u003e\u003e .env\n    echo SECRET_KEY=$(openssl rand -hex 32) \u003e\u003e .env\n\nTo run the web application in debug use::\n\n    alembic upgrade head\n    uvicorn app.main:app --reload\n\nIf you run into the following error in your docker container:\n\n   sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: No such file or directory\n   Is the server running locally and accepting\n   connections on Unix domain socket \"/tmp/.s.PGSQL.5432\"?\n\nEnsure the DATABASE_URL variable is set correctly in the `.env` file.\nIt is most likely caused by POSTGRES_HOST not pointing to its localhost.\n\n   DATABASE_URL=postgresql://postgres:postgres@0.0.0.0:5432/rwdb\n\n\n\nRun tests\n---------\n\nTests for this project are defined in the ``tests/`` folder.\n\nSet up environment variable ``DATABASE_URL`` or set up ``database_url`` in ``app/core/settings/test.py``\n\nThis project uses `pytest\n\u003chttps://docs.pytest.org/\u003e`_ to define tests because it allows you to use the ``assert`` keyword with good formatting for failed assertations.\n\n\nTo run all the tests of a project, simply run the ``pytest`` command: ::\n\n    $ pytest\n    ================================================= test session starts ==================================================\n    platform linux -- Python 3.8.3, pytest-5.4.2, py-1.8.1, pluggy-0.13.1\n    rootdir: /home/some-user/user-projects/fastapi-realworld-example-app, inifile: setup.cfg, testpaths: tests\n    plugins: env-0.6.2, cov-2.9.0, asyncio-0.12.0\n    collected 90 items\n\n    tests/test_api/test_errors/test_422_error.py .                                                                   [  1%]\n    tests/test_api/test_errors/test_error.py .                                                                       [  2%]\n    tests/test_api/test_routes/test_articles.py .................................                                    [ 38%]\n    tests/test_api/test_routes/test_authentication.py ..                                                             [ 41%]\n    tests/test_api/test_routes/test_comments.py ....                                                                 [ 45%]\n    tests/test_api/test_routes/test_login.py ...                                                                     [ 48%]\n    tests/test_api/test_routes/test_profiles.py ............                                                         [ 62%]\n    tests/test_api/test_routes/test_registration.py ...                                                              [ 65%]\n    tests/test_api/test_routes/test_tags.py ..                                                                       [ 67%]\n    tests/test_api/test_routes/test_users.py ....................                                                    [ 90%]\n    tests/test_db/test_queries/test_tables.py ...                                                                    [ 93%]\n    tests/test_schemas/test_rw_model.py .                                                                            [ 94%]\n    tests/test_services/test_jwt.py .....                                                                            [100%]\n\n    ============================================ 90 passed in 70.50s (0:01:10) =============================================\n    $\n\nIf you want to run a specific test, you can do this with `this\n\u003chttps://docs.pytest.org/en/latest/usage.html#specifying-tests-selecting-tests\u003e`_ pytest feature: ::\n\n    $ pytest tests/test_api/test_routes/test_users.py::test_user_can_not_take_already_used_credentials\n\nDeployment with Docker\n----------------------\n\nYou must have ``docker`` and ``docker-compose`` tools installed to work with material in this section.\nFirst, create ``.env`` file like in `Quickstart` section or modify ``.env.example``.\n``POSTGRES_HOST`` must be specified as `db` or modified in ``docker-compose.yml`` also.\nThen just run::\n\n    docker-compose up -d db\n    docker-compose up -d app\n\nApplication will be available on ``localhost`` in your browser.\n\nWeb routes\n----------\n\nAll routes are available on ``/docs`` or ``/redoc`` paths with Swagger or ReDoc.\n\n\nProject structure\n-----------------\n\nFiles related to application are in the ``app`` or ``tests`` directories.\nApplication parts are:\n\n::\n\n    app\n    ├── api              - web related stuff.\n    │   ├── dependencies - dependencies for routes definition.\n    │   ├── errors       - definition of error handlers.\n    │   └── routes       - web routes.\n    ├── core             - application configuration, startup events, logging.\n    ├── db               - db related stuff.\n    │   ├── migrations   - manually written alembic migrations.\n    │   └── repositories - all crud stuff.\n    ├── models           - pydantic models for this application.\n    │   ├── domain       - main models that are used almost everywhere.\n    │   └── schemas      - schemas for using in web routes.\n    ├── resources        - strings that are used in web responses.\n    ├── services         - logic that is not just crud related.\n    └── main.py          - FastAPI application creation and configuration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsidnev%2Ffastapi-realworld-example-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsidnev%2Ffastapi-realworld-example-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsidnev%2Ffastapi-realworld-example-app/lists"}