What database to use with Python
With so many options for databases, which is the best database for Python? The Python database you choose depends on your use case.
Relational databases like MySQL and PostgreSQL can be a good choice if you're dealing with data models that have a fixed structure (think: “tables”) — that is, the set of attributes for any given model changes rarely. In practice, this is very unusual while an application is under active development. A relational database, as you might expect, is also often the best choice for highly interrelated data.
For example, consider a school database to manage teachers, students, and courses. Teachers will have IDs, names, basic contact information, and maybe a role (“homeroom,” “substitute”). Students will have a similar set of attributes. Courses might have titles, descriptions, start and end dates, and so on. Most likely, though, these sets of attributes for each model will not change very much for the purposes of your application, and it's pretty likely that each record will have all of its attributes.
This type of data structure lends itself well to management by a relational database system (like MySQL or PostgreSQL). For smaller-scale applications, or for local testing, SQLite is also a good option to use.
When your data structure might be more fluid, with a schema that is less fixed, a document database like MongoDB might be the best database to use with Python for web development. With their document-oriented (as opposed to table-oriented) structure, document databases support a varying data structure easily; some records might have certain attributes, while other records don't have those attributes. Non-relational databases like MongoDB can store large amounts of data with varying structures. It's easily scalable, flexible, and relatively simple for beginners. Although MongoDB supports modeling and querying relationships between documents, it really excels when you wish to embed related data within a document itself.
For our tutorial, let's take a look at how you might import data from a cryptocurrency API into a MongoDB collection using Python. To see how easy it is to get started with Python, let's first create a database on MongoDB Atlas.