{"id":25268248,"url":"https://github.com/khailas12/fastapi-with-asynchronous-sqlalchemy","last_synced_at":"2026-02-09T05:37:23.101Z","repository":{"id":275648351,"uuid":"926740172","full_name":"Khailas12/FastAPI-with-Asynchronous-SQLAlchemy","owner":"Khailas12","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-03T19:51:29.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-03T20:33:20.207Z","etag":null,"topics":["alembic","asynchronous","fastapi-crud","postgresql","pydantic","sqlalchemy"],"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/Khailas12.png","metadata":{"files":{"readme":"readme.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-03T19:25:27.000Z","updated_at":"2025-02-03T19:53:26.000Z","dependencies_parsed_at":"2025-02-03T20:45:19.459Z","dependency_job_id":null,"html_url":"https://github.com/Khailas12/FastAPI-with-Asynchronous-SQLAlchemy","commit_stats":null,"previous_names":["khailas12/fastapi-with-asynchronous-sqlalchemy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Khailas12%2FFastAPI-with-Asynchronous-SQLAlchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Khailas12%2FFastAPI-with-Asynchronous-SQLAlchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Khailas12%2FFastAPI-with-Asynchronous-SQLAlchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Khailas12%2FFastAPI-with-Asynchronous-SQLAlchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Khailas12","download_url":"https://codeload.github.com/Khailas12/FastAPI-with-Asynchronous-SQLAlchemy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238453329,"owners_count":19475058,"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","asynchronous","fastapi-crud","postgresql","pydantic","sqlalchemy"],"created_at":"2025-02-12T10:24:25.223Z","updated_at":"2026-02-09T05:37:23.070Z","avatar_url":"https://github.com/Khailas12.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI with Asynchronous SQLAlchemy  \nA modern FastAPI application showcasing seamless integration with Asynchronous SQLAlchemy, enabling efficient CRUD operations with PostgreSQL.  \n\n## Features\n- 🚀 FastAPI for high-performance API development\n- 🐘 Async SQLAlchemy for database operations\n- 🗄️ PostgreSQL database support\n- 📄 Alembic for database migrations\n- 🛠️ Pydantic for data validation and serialization\n- 🧩 Modular architecture with clear separation of concerns\n\n## Getting Started  \n### Clone the Repository  \nTo get started, clone the repository to your local machine:  \n```bash\ngit clone https://github.com/Khailas12/FastAPI-with-Asynchronous-SQLAlchemy.git\ncd FastAPI-with-Asynchronous-SQLAlchemy\n```  \n## Project Structure\n```\n├── app/                     # Main application directory\n│ ├── alembic/               # Database migration scripts\n│ ├── core/                  # Core configurations\n│ ├── db/                    # Database models and session management\n│ ├── services/              # Business logic and API endpoints\n│ ├── utils/                 # Utility functions\n│ ├── alembic.ini            # Alembic configuration\n│ ├── main.py                # Application entry point\n│ └── __init__.py            # Package initialization\n├── .env                     # Environment variables\n└── README.md                # Project documentation\n```\n\n## Setup\n1. **Create a Virtual Environment**  \n   - **Linux/macOS**:  \n     ```bash\n     python3 -m venv venv\n     source venv/bin/activate\n     ```  \n   - **Windows**:  \n     ```cmd\n     python -m venv venv\n     .\\venv\\Scripts\\activate\n     ```  \n\n2. **Install Dependencies**  \n   Install the required Python packages:  \n   ```bash\n   pip install -r requirements.txt\n   ```  \n\n3. **Create the PostgreSQL Database**  \n   Before running the application, ensure the database is created. You can do this using:  \n\n   - **Command Line (psql)**:  \n     ```bash\n     psql -U your_db_user -h your_db_host -p 5432 -c \"CREATE DATABASE your_db_name;\"\n     ```  \n     Replace `your_db_user`, `your_db_host`, and `your_db_name` with your actual credentials.  \n\n   - **DBeaver**:  \n     1. Open DBeaver and connect to your PostgreSQL server.  \n     2. Right-click on \"Databases\" in the navigation tree.  \n     3. Select \"Create New Database\".  \n     4. Enter the database name (e.g., `fastapi_db`) and click \"OK\".  \n\n   - **pgAdmin**:  \n     1. Open pgAdmin and connect to your PostgreSQL server.  \n     2. Expand the \"Databases\" node in the browser tree.  \n     3. Right-click on \"Databases\" and select \"Create \u003e Database\".  \n     4. Enter the database name (e.g., `fastapi_db`) and click \"Save\".  \n\n4. **Verify Database Connection**  \n   Ensure the database is accessible using:  \n\n   - **Command Line (psql)**:  \n     ```bash\n     psql -U your_db_user -h your_db_host -p 5432 -d your_db_name\n     ```  \n     If successful, you’ll be able to interact with the database directly.  \n\n   - **DBeaver**:  \n     1. Open DBeaver and connect to your PostgreSQL server.  \n     2. Expand the \"Databases\" node and verify the new database appears.  \n     3. Test the connection by running a simple query (e.g., `SELECT 1;`).  \n\n   - **pgAdmin**:  \n     1. Open pgAdmin and connect to your PostgreSQL server.  \n     2. Expand the \"Databases\" node and verify the new database appears.  \n     3. Open the Query Tool and run a simple query (e.g., `SELECT 1;`) to test the connection.  \n\n5. **Environment Variables**  \n   Create a `.env` file with the following variables to configure your PostgreSQL database connection:  \n   ```env\n   DB_USER=your_db_user          # PostgreSQL username (e.g., \"postgres\")\n   DB_PASSWORD=your_db_password  # PostgreSQL password\n   DB_HOST=your_db_host          # Database host (e.g., \"localhost\" or \"127.0.0.1\")\n   DB_PORT=5432                  # Default PostgreSQL port\n   DB_NAME=your_db_name          # Database name (e.g., \"fastapi_db\")\n   ```\n\n6. **Database Migrations**\n   ```bash\n   alembic upgrade head\n   ```\n\n7. **Run the Application**\n   ```bash\n   uvicorn app.main:app --reload\n   ```\n\n## Database Migrations with Alembic\n### Initializing Alembic\nTo initialize Alembic in your project, run:\n```bash\nalembic init alembic\n```\n\nThis creates the following structure:\n```\nalembic/\n├── env.py\n├── script.py.mako\n└── versions/\nalembic.ini\n```\n\n### Configuration\n1. **alembic.ini** - Main configuration file\n   - Update `sqlalchemy.url` to use your database connection string\n   - Configure other settings like logging and migration paths\n\n2. **env.py** - Migration environment script\n   - Set up your SQLAlchemy models and database connection\n   - Configure the target metadata for migrations\n\n### Creating Migrations\nTo create a new migration:\n```bash\nalembic revision --autogenerate -m \"description of changes\"\n```\n\nThis will:\n1. Compare your models with the current database state\n2. Generate a migration script in the `versions/` directory\n3. Include the necessary SQL operations to update the schema\n\n### Applying Migrations\nTo apply pending migrations:\n```bash\nalembic upgrade head\n```\n\n### Common Commands\n- **Check current revision**: `alembic current`\n- **Upgrade to specific revision**: `alembic upgrade \u003crevision\u003e`\n- **Downgrade migrations**: `alembic downgrade \u003crevision\u003e`\n- **Show migration history**: `alembic history`\n- **Create empty migration**: `alembic revision -m \"description\"`\n\n\n### Best Practices\n1. Always review auto-generated migrations before applying them\n2. Test migrations in a development environment before production\n3. Use descriptive migration messages\n4. Keep migrations small and focused\n5. Never modify migrations after they've been applied to production\n\n\n## CRUD API Endpoints\n### Items\n- `POST /items/` - Create a new item\n- `GET /items/{item_id}` - Get item details\n- `PUT /items/{item_id}` - Update an item\n- `DELETE /items/{item_id}` - Delete an item\n\n\n## Technologies Used\n- [FastAPI](https://fastapi.tiangolo.com/)\n- [SQLAlchemy](https://www.sqlalchemy.org/)\n- [Alembic](https://alembic.sqlalchemy.org/)\n- [Pydantic](https://pydantic-docs.helpmanual.io/)\n- [PostgreSQL](https://www.postgresql.org/)\n- [Uvicorn](https://www.uvicorn.org/)\n\n\n## Contributing\nI welcome contributions from the open-source community! Whether you're fixing bugs, improving documentation, or adding new features, your help is greatly appreciated.\n1. Fork the repository\n2. Create a new branch (`git checkout -b feature/YourFeatureName`)\n3. Commit your changes (`git commit -m 'Add some feature'`)\n4. Push to the branch (`git push origin feature/YourFeatureName`)\n5. Open a pull request\n\n## License  \nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhailas12%2Ffastapi-with-asynchronous-sqlalchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhailas12%2Ffastapi-with-asynchronous-sqlalchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhailas12%2Ffastapi-with-asynchronous-sqlalchemy/lists"}