Introduction to Databases in Python
Query, filter, join and update relational databases from Python with SQLAlchemy and raw SQL, ending in a census database project.
SQLAlchemy gives Python code a way to read from, create and change relational databases such as SQLite, MySQL and PostgreSQL. The first queries are written both as raw SQL and through SQLAlchemy, so the SQL behind the Python calls stays visible. Later work adds filtering, joins and calculated values, then tables you design and keep up to date yourself.
What You Will Achieve
- Connect to SQLite, PostgreSQL and MySQL databases from Python and pull table data into your code
- Answer questions such as population totals by state with SQLAlchemy queries and plot the answers with pandas
- Set up new tables with constraints and keep their data current as records change or are removed
- Compare census figures across years by building, loading and querying a database of your own
Program Overview
Relational Databases and SQLAlchemy Basics
Starts with the relational model and how Python reaches a database through an engine, then selects data both ways.
- Relational model, engines and connection strings
- Autoloading tables and viewing table details
- Selecting data in raw SQL and SQLAlchemy
- Handling a ResultSet
Filtering, Grouping, Joins and Advanced Queries
Builds more precise queries, then moves to calculations, table relationships and very large result sets.
- Filtering and ordering query results
- Counting, summing and grouping, with pandas plots
- Calculated values and joins across relationships
- Hierarchical tables, aliases and large ResultSets
Building Databases and the Census Case Study
Covers creating and maintaining your own tables, then combines every skill in a census project.
- Creating tables with constraints and data defaults
- Inserting rows and loading a CSV into a table
- Updating and deleting records and whole tables
- Census case study: populating and querying a database
Certificate Awarded (Paid)
Job Outlook
Querying databases from Python is part of the work of analysts, data scientists and engineers who pull figures from relational databases into scripts, reports and pandas analysis.
Good for: Python users who want to reach relational databases from their own scripts and see raw SQL set beside SQLAlchemy.
Keep in mind: No SQL background is needed, since basic queries are taught alongside SQLAlchemy, but the lessons expect intermediate Python; much of the practice data is census tables by state.
Bottom line: Opening with raw SQL beside SQLAlchemy and closing with a census database loaded from a CSV, it covers both querying and building databases in Python.
Frequently Asked Questions
Which databases does the course connect to?
The lessons work with SQLite, PostgreSQL and MySQL. A PostgreSQL connection opens the chapter on filtering and ordering, and a MySQL connection opens the chapter on calculated values and joins.
Does the course teach raw SQL or only SQLAlchemy?
Both appear. The opening chapter selects data from a table in raw SQL and then with SQLAlchemy, so each Python call can be read against the SQL statement it stands for.
What happens in the census case study?
You set up the engine and metadata, create a table, read census data from a CSV and load it, then query it for average age, population share by gender and state, and changes between the 2000 and 2008 censuses.
How are very large query results handled?
A lesson on large ResultSets shows how to work through records in blocks. It sits in the chapter that also covers joins, aliases and hierarchical tables.
User Reviews
Write your review
You must be logged in to post a review.
Reviews can only be posted by registered learners. Log in or create a free account, then you will return here to post.


There are no reviews yet.