Uncategorized
Understanding Python’s Numeric Types
Numeric data types in Python are used to store numeric values. Python has four defined numeric types: plain integers, long integers, floating values, and complex numbers. The int type (plain integers) represents whole numbers that can be either positive or negative. The long type (long integers) are integers of infinite size. They’re written as whole […]
Read MoreHow to Use the Enumerate() Function
Iterables are undoubtedly some of the most valuable objects in Python. They’re incredibly versatile, helping solve a large assortment of problems. Looping through iterables is an extremely common task, but keeping track of the current element’s index typically demands writing more code. This is why the enumerate() function was built into Python all the way […]
Read MoreThe Basics: When to Use the del Statement
Using the del statement is relatively straightforward: it’s used to delete something. Often it’s used to remove an item from a list by referring to the item’s index rather than its value. For example, if you have the following list: list = [4, 8, 2, 3, 9, 7] And you want to remove the number […]
Read MoreMigrate SQLAlchemy Databases with Alembic
Alembic Alembic is a lightweight database migration tool for SQLAlchemy. It is created by the author of SQLAlchemy and it has become the de-facto standard tool to perform migrations on SQLAlchemy backed databases. Database Migration in SQLAlchemy A database migration usually changes the schema of a database, such as adding a column or a constraint, […]
Read MoreSQLAlchemy Expression Language, More Advanced Usage
Overview In the previous article SQLAlchemy Expression Language, Advanced Usage, we learned the power of SQLAlchemy’s expression language through a three table database including User, ShoppingCart, and Product. In this article, we are going to review the concept of materialised path in SQLAlchemy and use it to implement product containing relationships, where certain products may […]
Read MoreSQLAlchemy Expression Language, Advanced Usage
Expression Language One of the core components of SQLAlchemy is the Expression Language. It is allows the programmer to specify SQL statements in Python constructs and use the constructs directly in more complex queries. Since the expression language is backend-neutral and comprehensively covers every aspect of raw SQL, it is closer to raw SQL than […]
Read MoreUnderstanding Python SQLAlchemy’s Session
What are SQLAlchemy Sessions? What does the Session do? One of the core concepts in SQLAlchemy is the Session. A Session establishes and maintains all conversations between your program and the databases. It represents an intermediary zone for all the Python model objects you have loaded in it. It is one of the entry points […]
Read MoreSQLAlchemy Association Tables
Association Tables In our previous articles, we used an association table to model many-to-many relationships between tables, such as the relationship between Department and Employee. In this article, we are going to dive deeper into the association table concept and see how we can use it to further solve more complicated problems. DepartmentEmployeeLink and Extra […]
Read MoreSQLAlchemy ORM Examples
ORM Recap In one of the previous articles, we briefly went through an example database with two tables department and employee where one department can have multiple employees and one employee can belong to arbitrary number of departments. We used several code snippets to demonstrate the power of SQLAlchemy’s expression language and show how to […]
Read MoreSQLAlchemy – Some Commonly Asked Questions
Common Questions Before we dive deeper into SQLAlchemy, let’s answer a possible list of questions regarding the ORM: Can you prevent SQLAlchemy from automatically creating a schema? Instead, can you bind SQLAlchemy models to an existing schema? Is there a performance overhead when using SQLAlchemy, compared to writing raw SQL? If so, how much? If […]
Read More