{"id":25527128,"url":"https://github.com/yanliu1111/fastapi-crud-app","last_synced_at":"2026-05-03T15:33:42.657Z","repository":{"id":298246328,"uuid":"931937560","full_name":"yanliu1111/fastapi-crud-app","owner":"yanliu1111","description":"🎉Complete built beyond the basics and dive into advanced API development with FastAPI. ","archived":false,"fork":false,"pushed_at":"2025-06-10T05:11:32.000Z","size":255,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-10T06:22:56.354Z","etag":null,"topics":["celery","crud","fastapi","neondb","redis","sqlalchemy"],"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/yanliu1111.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,"zenodo":null}},"created_at":"2025-02-13T05:10:58.000Z","updated_at":"2025-06-10T05:11:35.000Z","dependencies_parsed_at":"2025-06-10T06:23:06.913Z","dependency_job_id":null,"html_url":"https://github.com/yanliu1111/fastapi-crud-app","commit_stats":null,"previous_names":["yanliu1111/fastapi-crud-app"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yanliu1111/fastapi-crud-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Ffastapi-crud-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Ffastapi-crud-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Ffastapi-crud-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Ffastapi-crud-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanliu1111","download_url":"https://codeload.github.com/yanliu1111/fastapi-crud-app/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Ffastapi-crud-app/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32575111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["celery","crud","fastapi","neondb","redis","sqlalchemy"],"created_at":"2025-02-19T22:17:14.630Z","updated_at":"2026-05-03T15:33:42.647Z","avatar_url":"https://github.com/yanliu1111.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI with CRUD operations\n\n\u003e📌**Learning Resource:** Based on the [FASTAPI BEYOND CRUD FULL COURSE](https://www.youtube.com/watch?v=TO4aQ3ghFOc\u0026t=30551s\u0026ab_channel=SsaliJonathan) — an excellent advanced FastAPI tutorial 👍. I extended the course by adding cloud-based Neon PostgreSQL, Redis configuration, and connection features not covered in the original content.\n\n\n### Project purpose\n\nStart by setting up a FastAPI project and running a simple web server. Then, progress to more advanced topics, including building REST APIs, handling path and query parameters, and working with databases using SQLModel. Additionally, explore managing settings with Pydantic, organizing your API with routers, and implementing asynchronous SQLModel connections.\n\n### ERD of the project\n```mermaid\nerDiagram\n    users {\n        UUID uid PK\n        varchar username\n        varchar email\n        varchar first_name\n        varchar last_name\n        varchar role\n        Boolean is_verified\n        varchar password_hash\n        Timestamp created_at\n        Timestamp update_at\n    }\n\n    books {\n        UUID uid PK\n        varchar title\n        varchar author\n        varchar publisher\n        Date published_date\n        Integer page_count\n        varchar language\n        Timestamp created_at\n        Timestamp updated_at\n        UUID user_id FK\n    }\n\n    reviews {\n        UUID uid PK\n        UUID book_id FK\n        UUID user_id FK\n        varchar review_text\n        Integer rating\n        Timestamp created_at\n    }\n\n    tag {\n        UUID uid PK\n        UUID book_id FK\n        varchar name\n        Timestamp created_at\n    }\n\n    users ||--o{ books : \"owns\"\n    users ||--o{ reviews : \"writes\"\n    books ||--o{ reviews : \"has\"\n    books ||--o{ tag : \"tagged\"\n```\n### Tech stack \u0026 workflow\n\n- FastAPI\n- Postgresql by [NEON](https://neon.tech/docs/guides/python) COULD BD (Set your Postgresql db in cloud)\n- ORM managed by SQLAlchemy\n- Data validating managed by Pydantic\n- CRUD With SQLModel\n- Alembic for migrations, offers good template for using async DB\n- passlib for password hashing\n- pydantic for data validation and settings management\n- pyjwt for JWT token management\n- Connect cloud Redis with FastAPI, set up Redis in cloud\n- Error Handling\n- Create custom API Exceptions\n- Creating a custom logging middleware\n- Adding CORS Middleware\n- Setting Up FastAPI-Mail\n- User account verification\n- Password Resets\n- FastAPI Background Tasks\n- Background Tasks with Celery and Redis\n- Celery Monitoring With Flower\n- API Documentation with SwaggerUI and Redoc `http://localhost:8000/docs`\n- API Testing\n- Unit testing with Unittest Mock and Pytest\n- Document-driven Testing with Schemathesis \n  - `pip install schemathesis`\n  - open `localhost:8000/api/v1/openapi.json`\n- Deployment on Render.com\n\n### Project setup\n1. Clone the project repository:\n```bash\ngit clone https://github.com/yanliu1111/fastapi-crud-app.git\n```\n\n2. Navigate to the project directory:\n```bash\ncd fastapi-crud-app/\n```\n\n3. Create a virtual environment:\n```bash\npython3 -m venv env\nsource env/bin/activate\n```\n\n4. Install the required dependencies:\n```bash\npip install -r requirements.txt\n```\n5. Create a `.env` file in the root directory and add Neon database URL:\n```bash\nDATABASE_URL=postgresql://\u003cusername\u003e:\u003cpassword\u003e@\u003chost\u003e:\u003cport\u003e/\u003cdatabase_name\u003e\nJWT_SECRET=#reference 8👉\nJWT_ALGORITHM=HS256\n```\n6. Run database migrations to initialize the database schema:\n```bash\nalembic revision --autogenerate -m\"add tag table\"\nalembic upgrade head\n```\n7. Run the FastAPI application:\n```bash\nfastapi dev src/\n```\n8. 👉JWT token generation:\n```bash\npython\nimport secrets\nsecrets.token_hex(16)\n```\n9. Redis connection:\n```js\n// in config.py\nimport os\nclass Settings(BaseSettings):\n    model_config = SettingsConfigDict(env_file=\".env\", extra=\"ignore\")\n    DATABASE_URL: str\n    JWT_SECRET: str\n    JWT_ALGORITHM: str\n    REDIS_HOST: str = os.getenv(\"REDIS_HOST\", \"localhost\")\n    REDIS_PORT: int = int(os.getenv(\"REDIS_PORT\", 6379))\n    REDIS_PASSWORD: str = os.getenv(\"REDIS_PASSWORD\", \"\")\n```\n\n10. Role-Based Access Control  \n    Admin \u003cbr\u003e\n    [\n        \"adding User\",\n        \"change roles\",\n        ”crud on users\",\n        \"book submission\",\n        \"crud on books\",\n        \"crud on reviews\",\n        \"revoke access\",\n    ]\u003cbr\u003e\n    User\u003cbr\u003e\n    [\n        \"crud on their own books submission\",\n        \"crud on their own reviews\",\n        \"crud on their own account\",\n    ]\n11. **lazy loading** - available via lazy = 'select' or the `lazyload()` option, this is the form of loading that emits a SELECT statement at attribute access time to lazily load a related reference on a signle object at a time. Lazy loading is detailed at lazy loading. \n\n12. How Celery works with FastAPI \u003cbr\u003e\nCelery is an asynchronous task queue/job queue that is based on distributed message passing. It is used to execute tasks in the background, allowing for the execution of long-running operations without blocking the main application thread. Celery supports multiple message brokers, such as RabbitMQ and Redis, and can be used with FastAPI to handle background tasks efficiently.\u003cbr\u003e\nBroker = Task Queue \u003cbr\u003e\nCelery Worker = Task Processor \u003cbr\u003e\nResults Backend = Task Result Storage \u003cbr\u003e\n![Celery](03-celery.excalidraw.png)\n\n`celery -A src.celery_tasks worker --loglevel=info` runs the Celery worker, which listens for tasks and executes them in the background. The `--loglevel=info` option sets the logging level to \"info\", providing detailed logs of task execution. \u003cbr\u003e\nopen a new terminal and run the following command to start the Celery worker:\n```bash\nsend_email(\n    recipients=['putyourtestemail@gmail.com'],\n    subject='testtest',\n    html_message='\u003ch1\u003esample message\u003ch1\u003e'\n)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanliu1111%2Ffastapi-crud-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanliu1111%2Ffastapi-crud-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanliu1111%2Ffastapi-crud-app/lists"}