{"id":24438757,"url":"https://github.com/ezeparziale/fastapi-api-template","last_synced_at":"2026-04-02T02:53:54.031Z","repository":{"id":58752600,"uuid":"532693231","full_name":"ezeparziale/fastapi-api-template","owner":"ezeparziale","description":":zap: Fastapi Api template","archived":false,"fork":false,"pushed_at":"2024-05-22T21:54:30.000Z","size":347,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-05-22T22:46:04.050Z","etag":null,"topics":["alembic","auth","bcrypt","black","coverage","docker","docker-compose","fastapi","google","isort","jwt","oauth2","postgres","pydantic","python","ruff","sqlalchemy","swagger"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ezeparziale.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-05T00:30:20.000Z","updated_at":"2024-05-30T00:37:54.897Z","dependencies_parsed_at":"2023-12-26T22:30:21.461Z","dependency_job_id":"80a28af8-d8d6-4ebc-9543-bfdbe9e58fbb","html_url":"https://github.com/ezeparziale/fastapi-api-template","commit_stats":null,"previous_names":["ezeparziale/fastapi-api-template"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezeparziale%2Ffastapi-api-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezeparziale%2Ffastapi-api-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezeparziale%2Ffastapi-api-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezeparziale%2Ffastapi-api-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezeparziale","download_url":"https://codeload.github.com/ezeparziale/fastapi-api-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610407,"owners_count":21132920,"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":["alembic","auth","bcrypt","black","coverage","docker","docker-compose","fastapi","google","isort","jwt","oauth2","postgres","pydantic","python","ruff","sqlalchemy","swagger"],"created_at":"2025-01-20T19:17:39.808Z","updated_at":"2026-04-02T02:53:54.009Z","avatar_url":"https://github.com/ezeparziale.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :zap: FastAPI API Template\n\n\nThis template provides a robust starting point for building APIs with FastAPI. It includes user authentication, CRUD operations, JWT token-based authentication, and PostgreSQL integration. The setup is streamlined with Docker and includes comprehensive documentation and testing tools.\n\n## :pushpin: Features\n\n- :closed_lock_with_key: User authentication with basic login and Google Auth\n- :busts_in_silhouette: User management with creation and CRUD operations\n- :page_facing_up: Example endpoints for Posts, Users, and Votes\n- :heartbeat: API healthcheck endpoint\n- :key: JWT token-based authentication\n- :gear: Middleware support\n- :earth_americas: CORS configuration\n- :memo: Comprehensive Swagger API documentation\n- :elephant: PostgreSQL database integration\n- :lock: Field encryption for sensitive data\n\n## :floppy_disk: Installation\n\n\u003e [!IMPORTANT]\n\u003e Min Python version: 3.14\n\nClone this repo:\n\n```bash\ngit clone https://github.com/ezeparziale/fastapi-api-template\n```\n\nCreate virtual environment:\n\n```bash\npython -m venv env\n```\n\nActivate environment:\n\n- Windows:\n\n```bash\n. env/scripts/activate\n```\n\n- Mac/Linux:\n\n```bash\n. env/bin/activate\n```\n\nUpgrade pip:\n\n```bash\npython -m pip install --upgrade pip\n```\n\nInstall requirements:\n\n```bash\npip install -r requirements-dev.txt\n```\n\nInstall pre-commit:\n\n```bash\npre-commit install\n```\n\n## :wrench: Config\n\nCreate `.env` file. Check the example `.env.example`\n\n:globe_with_meridians: Google Auth credentials:\n\nCreate your app and obtain your `client_id` and `secret`:\n\n```http\nhttps://developers.google.com/workspace/guides/create-credentials\n```\n\n:lock: How to create a secret key:\n\n```bash\nopenssl rand -base64 64\n```\n\n:closed_lock_with_key: How to create an encryption key:\n\nTo create an encryption key for securing sensitive data, you can use the `generate_key.py` script provided in the repository. Run the following command:\n\n```bash\npython generate_key.py\n```\n\nThis will generate a secure encryption key.\n\n:construction: Before first run:\n\nRun `docker-compose` :whale: to start the database server\n\n```bash\ndocker compose -f \"compose.yaml\" up -d --build adminer db\n```\n\nand init the database with alembic:\n\n```bash\nalembic upgrade head\n```\n\n:key: Create a self-signed certificate with openssl:\n\n```bash\nopenssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365\n```\n\n## :runner: Run\n\n```bash\nuvicorn app.main:app --reload --port 8000 --ssl-keyfile key.pem --ssl-certfile cert.pem\n```\n\n## :rotating_light: Lint\n\nRun linter and formatter\n\n```bash\nscripts/lint.sh\n```\n\n```bash\nscripts/format.sh\n```\n\n## :technologist: Coverage\n\nRun coverage\n\n```bash\ncoverage run -m pytest\n```\n\n```bash\ncoverage report --show-missing\n```\n\n```bash\ncoverage html\n```\n\nOr run all in one with:\n\n```bash\nscripts/coverage.sh\n```\n\n## :test_tube: Test\n\nRun pytest with coverage\n\n```bash\ncoverage run -m pytest\n```\n\nor\n\n```bash\nscripts/test.sh\n```\n\n## :hammer_and_wrench: Alembic\n\nAlembic is used for database migrations. Below are some common commands to manage your database schema.\n\n### Autogenerate a revision\n\nTo autogenerate a new revision based on the changes detected in your models, run:\n\n```bash\nalembic revision --autogenerate -m \"your message here\"\n```\n\n### Generate a blank revision\n\nTo create a blank revision for custom migrations, run:\n\n```bash\nalembic revision -m \"your message here\"\n```\n\n### Upgrade the database\n\nTo apply the latest migrations and upgrade the database schema, run:\n\n```bash\nalembic upgrade head\n```\n\n### Downgrade the database\n\nTo revert the last migration and downgrade the database schema, run:\n\n```bash\nalembic downgrade -1\n```\n\nAfter creating a revision, you can edit the generated script to define your custom migrations.\n\n## :bar_chart: Monitoring\n\nThis project includes a complete observability stack using **Grafana**, **Loki**, and **Promtail**.\n\n### :rocket: Setup\n\n1.  **Start the monitoring stack**:\n    ```bash\n    docker compose up -d grafana loki promtail\n    ```\n\n2.  **Access Grafana**:\n    Open [http://localhost:3000](http://localhost:3000) in your browser.\n    - **Default credentials**: `admin` / `admin`\n\n3.  **Add Loki Data Source**:\n    - Go to **Connections** \u003e **Data sources**.\n    - Click **Add data source** and select **Loki**.\n    - Set the **URL** to: `http://loki:3100`.\n    - Click **Save \u0026 test**.\n\n### :level_slider: Create Dashboard with Variables\n\nTo visualize logs efficiently, follow these steps to create a dashboard with a level filter:\n\n1.  **Create a New Dashboard**:\n    - Click the **+** icon \u003e **Dashboard**.\n1.  **Add a Variable for Log Level**:\n    - Go to **Dashboard Settings** (gear icon) \u003e **Variables**.\n    - Click **Add variable**.\n    - **Name**: `level`\n    - **Type**: `Custom`\n    - **Custom options (Values separated by comma)**: `TRACE,DEBUG,INFO,SUCCESS,WARNING,ERROR,CRITICAL`\n    - Click **Apply**.\n2.  **Add a Logs Panel**:\n    - Add a new **Visualization**.\n    - Select **Loki** as the data source.\n    - Use the following **LogQL** query:\n      ```logql\n      {container=\"app\"} | json | record_level_name =~ \"$level\" | line_format \"{{.record_message}}\"\n      ```\n    - This query filters logs by the `app` container, parses the JSON format, filters by the selected `$level` variable, and cleans up the output message.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezeparziale%2Ffastapi-api-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezeparziale%2Ffastapi-api-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezeparziale%2Ffastapi-api-template/lists"}