---
title: "Discussion on \"Patterns and Practices for using SQLAlchemy 2.0 with FastAPI\" | Hashnode"
description: "Discussion on \"Patterns and Practices for using SQLAlchemy 2.0 with FastAPI\". FastAPI and SQLAlchemy: a match made in heaven. The freedom, simplicity, and flexibility they offer make them one of the best options for Python projects"
url: "https://hashnode.com/posts/fastapi-sqlalchemy/648b2aeb8a365cbd5dbe45f9"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Patterns and Practices for using SQLAlchemy 2.0 with FastAPI](https://chaoticengineer.hashnode.dev/fastapi-sqlalchemy?utm_source=hashnode&utm_medium=feed)

FastAPI and SQLAlchemy: a match made in heaven. The freedom, simplicity, and flexibility they offer make them one of the best options for Python projects

Jun 15, 2023 · 19 min read · chaoticengineer.hashnode.dev  
Updated Jun 7, 2024  
Read the article

-   [#python](https://hashnode.com/tag/python)
-   [#fastapi](https://hashnode.com/tag/fastapi)
-   [#sqlalchemy](https://hashnode.com/tag/sqlalchemy)

## Written by

[Piotr Tobiasz](https://hashnode.com/@tobias-piotr)

@tobias-piotr · Berlin

  
[View profile](https://hashnode.com/@tobias-piotr)

Backend Engineer

Engineering enjoyer. Having fun with Python, Go, and software design and architecture. Reading a lot of fantasy and nonfiction. Love to share my knowledge with others.

## Responses 3

Markdown supported · ⌘↵ to post

[Andres Cárdenas](https://hashnode.com/@afc)

[Mar 25, 2025](https://hashnode.com/posts/fastapi-sqlalchemy/648b2aeb8a365cbd5dbe45f9/comment/67e3227715cd223c6fe341a9)

Hi good tutorial. But when i ran the project with docker compose the tables does not exists. And when i tried with the make migrate command i am getting this error: ModuleNotFoundError: No module named 'alchemist' make: _\*_ \[migrate\] Error 1

[Mahmudul Hassan](https://hashnode.com/@mahmudul5809)

[Sep 29, 2024](https://hashnode.com/posts/fastapi-sqlalchemy/648b2aeb8a365cbd5dbe45f9/comment/66f91df4e98dcdf683e56e5d)

hey thanks for the article . One question :

you add await session.commit() in both get\_db\_session function also in router method like create\_ingredient . can you explain this please? Thanks

[Rei Liu](https://hashnode.com/@reiplay)

[Dec 8, 2023](https://hashnode.com/posts/fastapi-sqlalchemy/648b2aeb8a365cbd5dbe45f9/comment/657341f439ab1abc35e2d1b8)

handcrafted writing all the way, no trace of ai generated unaudited stuff whatsoever; followed production level best practices, like v1, v2 versioning; modern and practical async usage everywhere; introduction to the repository pattern; the python generic, async and testing stuff is kinda advanced, but really encourages and pushes learner to get into these areas of the language.

it would be nicer if links are provide on some of the crucial concepts and keywords, make it more beginner friendly.

and finally, I really liked the alchemist themed example project. And I think mike bayer said it somewhere in a video, that the Alchemy metaphor is embedded into the philosophy of sqlalchemy. think about the querying method chaining or other things, it's like doing alchemy… :)))

sorry for the long comment. thanks, Piotr, for this fantastic article. love the banner arts btw. <3

[Piotr Tobiasz](https://hashnode.com/@tobias-piotr)

[Dec 8, 2023](https://hashnode.com/posts/fastapi-sqlalchemy/648b2aeb8a365cbd5dbe45f9/comment/657341f439ab1abc35e2d1b8#reply-657369c117e07d7a03568c26)

Thank you for the comment Rei, really appreciate it!
