Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Python Database Mastery: Dive into SQLAlchemy & Alembic
Rating: 4.2 out of 5(389 ratings)
3,179 students

Python Database Mastery: Dive into SQLAlchemy & Alembic

Master SQLAlchemy & Alembic: Easily Create/Manage Databases, Implement ORM, Use Migration Tool, Boost Query Performance
Last updated 10/2023
English

What you'll learn

  • Understand the fundamentals of SQLAlchemy and Object Relational Mapping (ORM) in Python
  • Create, define, and manage database tables using SQLAlchemy's ORM
  • Utilize Alembic, a database migration tool for SQLAlchemy, to create, manage, and track changes in their database schema
  • Apply best practices for using SQLAlchemy and Alembic in real-world projects

Course content

6 sections31 lectures3h 56m total length
  • Introduction to the course3:48

    Introduce SQLAlchemy 2.0 and Alembic for database building and migrations, explore synchronous and asynchronous connections, and integrate with a telegram bot using Gram across Postgres and other backends.

  • Introduction to SQLAlchemy and Alembic
  • Section 1 - Jupyter Notebook0:03
  • Setting Up Virtual Environment and Required Libraries5:55

    Learn to set up a Python 3.10 environment with a virtual environment in PyCharm, install PostgreSQL via Docker or locally, and configure SQLAlchemy with psycopg2 and its binary.

  • Setting Up PostgreSQL with Docker3:55

    Set up a PostgreSQL database in a Docker container using the PostgreSQL 13.4 Alpine image, configuring environment variables for user, password, and database, and verify the instance is ready.

  • Establishing Database Connection11:50

    Establish a PostgreSQL connection with SQLAlchemy by creating an engine, building a URL, and using a session pool to execute text queries and manage transactions.

Requirements

  • Basic Python programming knowledge: Understanding of Python data types, functions, classes, and syntax is essential for following the tutorial.
  • Familiarity with SQL: Learners should have a basic understanding of SQL concepts like tables, primary keys, foreign keys, and CRUD operations (Create, Read, Update, and Delete).
  • Object-Oriented Programming (OOP) understanding: Since the tutorial uses Object Relational Mapping (ORM) for creating tables, having some experience with OOP and Python classes would be beneficial.
  • Python environment: Learners should have a Python development environment set up on their machine (Python 3.x and pip) or have access to a Jupyter Notebook environment where they can install packages and run code snippets as demonstrated in the tutorial
  • Database access: Access to a PostgreSQL database server for hands-on practice is crucial. Familiarity with creating databases and user accounts would be useful but not required, as it can be learned along the way.

Description

This comprehensive course is designed for users who have some knowledge of SQL, and it aims to teach you how to leverage the power of SQLAlchemy and Alembic to streamline your work with databases. By learning the techniques taught in this course, you will have a better understanding of Object Relational Mapping (ORM), how to create and manipulate database tables using Python, and how to manage and track changes using Alembic migrations.


Throughout the course, you will gain hands-on experience by working on various practical examples and exercises. The course will be easy to follow, with a focus on making complex tasks easier to understand and apply in your own projects.


Key topics include:


1. Introduction to SQLAlchemy and Alembic

    - Overview of SQLAlchemy and its benefits

    - Getting started with Alembic for database migrations


2. Creating tables with SQLAlchemy

    - Declarative base and table class creation

    - Working with different column types and constraints

    - Using Mixin classes to reuse column and key definitions


3. Working with data using ORM

    - Inserting, updating, and deleting rows

    - Querying data and using filtering options

    - Working with relationships and joins.


4. Handling schema changes and migrations with Alembic

    - Setting up an Alembic environment and configuration

    - Generating, reviewing, and customizing migration scripts

    - Upgrading and downgrading database schemas


5. Advanced SQLAlchemy features

    - Query optimizations

    - Building complex queries

    - Managing transactions and session handling


6. Best practices and real-world case examples

    - Implementing reusable patterns

    - Scaling and performance considerations

    - Common SQLAlchemy pitfalls and solutions


Upon completion of this course, you will have a strong foundation in using SQLAlchemy and Alembic to manage your databases effectively. You will be equipped with the skills necessary to create and manipulate databases with ease, enabling you to bring value to your projects and organization.

Who this course is for:

  • SQL users wanting Python ORM skills
  • Developers seeking Pythonic DB management
  • Data engineers improving DB knowledge
  • SQLAlchemy newbies with SQL background
  • App developers needing DB integration
  • Python programmers with SQL experience
  • Transitioning SQL users to SQLAlchemy