Python for .NET Developers Transcripts
Chapter: Database access and ORMs in Python
Lecture: Databases and Python

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Databases are central to most applications especially server side applications like websites and Web APIs.
0:09 So when you think about working with a database there's a really good chance that in the .NET world
0:15 your thinking Entity Framework and Microsoft SQL Server. That's the most common way in which we work with databases.
0:23 Yeah you can do, just open up a connection and do select * from table, et cetera. That is direct SQL type queries. People do it but
0:33 and there's reasons you might want to do it but, most of the time, you want to use an ORM and in .NET the ORM most of the time is Entity Framework.
0:41 We saw what happened when we had this one thing in .NET and went over to Python in the web world it exploded in to a huge number
0:50 of these different frameworks. Sort of true in Python as well, but it actually turned out to be a little more focused. In Python
0:56 we have two primary relational database access ORMs for us. If you're using Django, there's a Django ORM. It's very likely you're going to use that.
1:07 If you're not using Django, most of the time people just assume you're using SQLAlchemy. SQLAlchemy has been around for a really long time
1:15 it's super popular and it works great. It's high performance. We're going to talk about a lot of the ways
1:20 in which it works and that's the one we're going to choose. If we jump back to our JetBrains PSF Survey from 2018
1:28 you can go and find the ORM section and see well, it's a pretty clear split here. If you're using Django you're going to be using Django ORM.
1:36 Other than that, chances are you're using SQLAlchemy. There are reasons to use other ones like peewee is pretty nice and peewee has good async support.
1:45 If you want to use, you know async in a way to with the database and SQLAlchemy doesn't have that built in. So there's reasons to choose others
1:50 but these are the primary two and the decision is do I have Django? Yes. Then I use Django ORM, otherwise, SQLAlchemy.
1:58 There's other things and other ways to access databases worth throwing out right now that, you know, for example, I said earlier
2:04 our site runs on MongoDB, and SQLAlchemy and Django those are for relational databases. They don't make sense. So we use Mongo Engine.
2:11 If you're using Redis or other databases that were not relational this might not be the choice you want to make
2:17 probably doesn't work with that database. Assuming you want to use a relational database here's what the landscape in Python looks like.

Talk Python's Mastodon Michael Kennedy's Mastodon