I'm exploring the possibility of using Tortoise ORM for my project because it seems easier to handle async database operations compared to SQLAlchemy. Plus, it has native support for FastAPI, which is a bonus. Has anyone actually used Tortoise ORM in a production environment? I'd love to hear your thoughts and experiences!
7 Answers
Just started looking into Tortoise. Seems interesting!
I didn't even know there were other ORMs besides SQLAlchemy! My team's been using SQLAlchemy and Alembic with solid test coverage, so I’m not quite sure what you mean by it being hard to test. We use PostgreSQL in a Docker container for our tests, which keeps things isolated and runs smoothly. Sure, some people really dislike ORMs, but honestly, SQLAlchemy is pretty battle-tested in professional scenarios. Just my two cents!
If you're exploring options, give Piccolo ORM a look! It’s been my preference for most projects lately. Definitely worth checking out!
I checked it out, but it feels like another ORM that doesn’t align with Python basics. We really need to do better in the community!
From what I’ve seen, SQLAlchemy is pretty test-friendly. If you're having trouble, you might need to reevaluate your setup.
What makes Tortoise ORM easier to test? Personally, I find Django's DB-connected testing annoying, but since I switched to Testcontainers, it’s not so bad. SQLAlchemy seems to keep the domain cleaner and can often be tested without direct I/O, which is a huge plus.
Actually, Django does allow you to isolate tests from the database. You just gotta choose the right test class!
I've been using Tortoise ORM in a production environment for a couple of years now, primarily because SQLAlchemy was slow to implement async support. While the core features of Tortoise are pretty solid, the integration with FastAPI and Pydantic has its quirks, although it's not essential. Don’t overlook the Tortoise migration tool; it’s quite handy even if it lags behind Alembic.
Honestly, I think SQLAlchemy isn’t that complicated to test. You can easily reconfigure your sessionmaker to point to a new engine. If your engine isn't referenced directly in the app, you’re golden! Alternatively, wrapping the engine in a container object for easier overrides is also an option.
Sounds like a solid strategy! I’m curious if any specific libraries helped with your setup.