{"id":31698830,"url":"https://github.com/luiz-trindade/fastapi_auto_routes","last_synced_at":"2026-04-18T17:34:34.107Z","repository":{"id":318181971,"uuid":"1070270953","full_name":"Luiz-Trindade/fastapi_auto_routes","owner":"Luiz-Trindade","description":"⚡ FastAPI Auto Routes — a smart CRUD \u0026 Auth generator for SQLModel 🚀 It builds secure, cache-powered REST APIs 🔒 with login, token-based auth 🪪, and async concurrency ⚙️. Cut boilerplate, boost productivity, and ship production-ready backends fast ⚡🔥","archived":false,"fork":false,"pushed_at":"2025-10-05T16:21:27.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-05T17:48:17.316Z","etag":null,"topics":["api-generator","async","asyncio","auth","backend","backend-development","caching","concurrency","crud","fastapi","jwt","microservice","pydantic","python","rest-api","scalable-api","sqlite","sqlmodel","sqlmodel-crud","token-based-auth"],"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/Luiz-Trindade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-05T15:58:20.000Z","updated_at":"2025-10-05T16:21:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ce70df2-e9b7-429d-bcc0-7c1c90a841d7","html_url":"https://github.com/Luiz-Trindade/fastapi_auto_routes","commit_stats":null,"previous_names":["luiz-trindade/fastapi_auto_routes"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Luiz-Trindade/fastapi_auto_routes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luiz-Trindade%2Ffastapi_auto_routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luiz-Trindade%2Ffastapi_auto_routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luiz-Trindade%2Ffastapi_auto_routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luiz-Trindade%2Ffastapi_auto_routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Luiz-Trindade","download_url":"https://codeload.github.com/Luiz-Trindade/fastapi_auto_routes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luiz-Trindade%2Ffastapi_auto_routes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000701,"owners_count":26082805,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api-generator","async","asyncio","auth","backend","backend-development","caching","concurrency","crud","fastapi","jwt","microservice","pydantic","python","rest-api","scalable-api","sqlite","sqlmodel","sqlmodel-crud","token-based-auth"],"created_at":"2025-10-08T19:11:05.735Z","updated_at":"2025-10-08T19:11:25.313Z","avatar_url":"https://github.com/Luiz-Trindade.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⚡ FastAPI Auto Routes  \n\u003e Dynamic CRUD \u0026 Auth Generator for SQLModel — single-file plug-and-play.\n\n[![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=flat\u0026logo=fastapi)](https://fastapi.tiangolo.com/)\n[![Python](https://img.shields.io/badge/Python-3.11%2B-blue?logo=python\u0026logoColor=white)](https://www.python.org/)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n[![SQLModel](https://img.shields.io/badge/SQLModel-compatible-success)](https://sqlmodel.tiangolo.com/)\n[![DiskCache](https://img.shields.io/badge/diskcache-enabled-orange)](https://grantjenks.com/docs/diskcache/)\n\n---\n\n## 🧠 Overview\n\n**FastAPI Auto Routes** is a **single-file dynamic router generator** (`auto_routes.py`) that eliminates repetitive CRUD boilerplate.  \nSimply download or import the file, configure your **SQLModel engine**, and you’re ready to generate full-featured **CRUD endpoints** with:\n\n- ✅ Authentication via Bearer tokens  \n- ⚡ Smart caching (with TTL)  \n- 🔄 Concurrency control  \n- 🧩 Bulk operations  \n- 🪪 Auto-generated `/login` and `/logout` routes  \n\nBuilt on **FastAPI + SQLModel + diskcache**, ready to plug into your project.\n\n---\n\n## 🚀 Installation\n\n```bash\n# Clone the repo\ngit clone https://github.com/yourusername/fastapi-auto-routes.git\n\ncd fastapi-auto-routes\n\n# Install dependencies\npip install -r requirements.txt\n```\n\nor using **Poetry**:\n\n```bash\npoetry add fastapi sqlmodel diskcache\n```\n\nSimply copy or import `auto_routes.py` into your project.\n\n---\n\n## ⚙️ Example Usage\n\n```python\nfrom fastapi import FastAPI\nfrom sqlmodel import SQLModel, Field\nfrom app.db.config import engine  # Configure your SQLModel engine\nfrom app.utils.auto_routes import crud_router\n\nclass User(SQLModel, table=True):\n    id: int | None = Field(default=None, primary_key=True)\n    email: str\n    password: str\n\n# Create tables\nSQLModel.metadata.create_all(engine)\n\napp = FastAPI()\n\n# 🔐 Auth Router (Login / Logout)\napp.include_router(\n    crud_router(User, login=True, login_fields=[\"email\", \"password\"]),\n    prefix=\"/auth\",\n    tags=[\"Auth\"]\n)\n\n# ⚙️ CRUD Router (Requires Token)\napp.include_router(\n    crud_router(User, auth=True, ttl=120, max_concurrent=8),\n    prefix=\"/users\",\n    tags=[\"Users\"]\n)\n```\n\n---\n\n## 🧩 Generated Routes\n\n| Route          | Method   | Description               | Auth Required |\n| -------------- | -------- | ------------------------- | ------------- |\n| `/auth/login`  | `POST`   | Generate session token    | No            |\n| `/auth/logout` | `POST`   | Invalidate active session | ✅             |\n| `/users/`      | `GET`    | Paginated list of users   | ✅             |\n| `/users/{id}`  | `GET`    | Get user by ID            | ✅             |\n| `/users/`      | `POST`   | Create user               | ✅             |\n| `/users/{id}`  | `PATCH`  | Update user               | ✅             |\n| `/users/{id}`  | `DELETE` | Delete user               | ✅             |\n\n---\n\n## ⚡ Parameters\n\n| Parameter        | Type             | Default       | Description                          |\n| ---------------- | ---------------- | ------------- | ------------------------------------ |\n| `model`          | `Type[SQLModel]` | —             | Your SQLModel class                  |\n| `ttl`            | `int \\| None`    | `None`        | Cache expiration time (seconds)      |\n| `max_concurrent` | `int \\| None`    | `cpu_count()` | Max concurrent operations            |\n| `login`          | `bool`           | `False`       | Enables `/login` and `/logout`       |\n| `login_fields`   | `List[str]`      | `None`        | Fields used for login validation     |\n| `login_ttl`      | `int`            | `3600`        | Token lifetime in seconds            |\n| `auth`           | `bool`           | `False`       | Requires Bearer token for all routes |\n\n---\n\n## 🧠 How It Works\n\n1. **Single-file CRUD \u0026 Auth Generation**\n   `crud_router()` dynamically builds all routes (`GET`, `POST`, `PATCH`, `DELETE`) for the given model from **one file**.\n\n2. **Authentication Layer**\n\n   * `/login`: validates credentials and creates a token stored in `sessions_cache`.\n   * `/logout`: invalidates the token.\n   * Protected routes require the header:\n\n     ```\n     Authorization: Bearer \u003ctoken\u003e\n     ```\n\n3. **Caching \u0026 Concurrency**\n\n   * Uses `diskcache` for persistent caching with optional TTL.\n   * Uses `asyncio.Semaphore` for safe concurrency limits per model.\n\n---\n\n## 📂 Project Structure\n\n```\napp/\n├── db/\n│   └── config.py          # Database engine setup\n├── utils/\n│   └── auto_routes.py     # Single-file router generator\n├── main.py                # FastAPI entrypoint\n```\n\n---\n\n## 🧰 Requirements\n\n* Python 3.11+\n* FastAPI\n* SQLModel\n* DiskCache\n* Uvicorn (for local testing)\n\n---\n\n## 🧞‍♂️ Philosophy\n\n\u003e **Automation without compromise.**\n\nInstead of repeating CRUD definitions across every model, this **single file** dynamically builds routers that are **secure**, **scalable**, and **production-ready**.\nYour backend becomes **data-driven**, not boilerplate-driven.\n\n---\n\n## 📜 License\n\nMIT License © 2025 Luiz Gabriel Magalhães Trindade\nFree for personal and commercial use.\n\n---\n\n## 🌐 Connect\n\n* 🧠 **Project Author:** Luiz Gabriel Trindade\n* 💼 GitHub: [@Luiz-Trindade](https://github.com/Luiz-Trindade)\n* 📧 Contact: [Email](mailto:luiz.gabriel.m.trindade@gmail.com)\n\n---\n\n### ⭐ If this file saves you time, give it a star — it’s the currency of open source.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluiz-trindade%2Ffastapi_auto_routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluiz-trindade%2Ffastapi_auto_routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluiz-trindade%2Ffastapi_auto_routes/lists"}