Flyway-Python
📋 Requirements
- Python 3.11+
🚀 Install
pip install flyway
NOTICE
If you are using MySQL and need to execute multiple SQL statements, make sure to add client_flag=CLIENT.MULTI_STATEMENTS in pymysql param. This is required to allow the execution of multiple SQL statements in a single query.
📖 Usage
Basic Example
import sqlite3
from flyway import Migrator, MigratorConfig, DbType
# Create database connection
conn = sqlite3.connect("example.db")
# Configure migrator
config = MigratorConfig(
db_type=DbType.SQLITE,
user="admin"
)
# Create migrator instance
migrator = Migrator(conn, config)
# Run migrations from db/migration folder
migrator.migrate()
MySQL Example
import pymysql
from pymysql.constants import CLIENT
from flyway import Migrator, MigratorConfig, DbType
# Create MySQL connection
# Note: Add client_flag=CLIENT.MULTI_STATEMENTS if your migration files contain multiple SQL statements
conn = pymysql.connect(
host="localhost",
user="root",
password="password",
database="mydb",
client_flag=CLIENT.MULTI_STATEMENTS
)
# Configure migrator
config = MigratorConfig(
db_type=DbType.MYSQL,
user="root"
)
# Create migrator instance
migrator = Migrator(conn, config)
# Run migrations from custom path
migrator.migrate_from_path("/path/to/migrations")
Migration File Naming
Migration files should follow the naming convention:
V<version>__<description>.sql
Examples:
V1_0__Create_users_table.sqlV1_1__Add_email_column.sqlV2_0__Create_posts_table.sql
The version format uses underscores (e.g., 1_0 for version 1.0).
Migration Directory Structure
By default, migrations are loaded from db/migration/ directory:
project/
├── db/
│ └── migration/
│ ├── V1_0__Create_users_table.sql
│ ├── V1_1__Add_email_column.sql
│ └── V2_0__Create_posts_table.sql
└── main.py
You can also specify a custom path using migrate_from_path() method.
Metadata
Release files for flyway 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flyway-0.2.0.tar.gz | 12.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flyway-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / flyway-0.2.0.tar.gz
| Download URL | flyway-0.2.0.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d53ac17a8fdc0ba586e12430d7adcd78ed7f257c99d2fc73d7f4eeaaefc49a73
|
|
BLAKE2b-256 checksum How to use checksums |
136785bd05fa6a0cdbb1dbc8feac3c29f89a801b1b3bb8ff5c9c2be533bbed69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.4
|
Release files / flyway-0.2.0-py3-none-any.whl
| Download URL | flyway-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
477da4bfad26a4cdc4d329a87f0df4eaa663818dc80cc509a2e4d0281addde98
|
|
BLAKE2b-256 checksum How to use checksums |
1bd247ef866974ffd26c1415b34426a7046321f3ddd6e1cdaf730c65686000c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.4
|