Caribou SQLite Migrations
Caribou is a small, simple SQLite database migrations library for Python, built primarily to manage the evolution of client side databases over multiple releases of an application.
Example
Here is a simple example illustrating how to use Caribou to manage your SQLite schema:
Create a Migration
Use Caribou's command line tool to create your first migration:
$ caribou create my_first_migration
created migration ./v20091115140758_my_first_migration.py
Edit Your Migration
Let's create a table with some data in the upgrade step and reverse the changes in the downgrade step.
"""
An example of a Caribou migration file.
"""
def upgrade(connection):
# connection is a plain old sqlite3 database connection
sql = """
create table animals
( name TEXT
, status TEXT
) """
connection.execute(sql)
animals = [ ('caribou', 'least concerned')
, ('bengal tiger', 'threatened')
, ('eastern elk', 'extinct')
]
sql = 'insert into animals values (?, ?)'
for name, status in animals:
connection.execute(sql, [name, status])
connection.commit()
def downgrade(connection):
connection.execute('drop table animals')
Caribou migrations are flexible because they are plain Python files. Feel free to add logging, DDL transactions, anything at all.
Run Your Migration:
Caribou migrations can be run with the command line tool:
$ caribou upgrade db.sqlite .
upgrading db [db.sqlite] to most recent version
upgraded [db.sqlite] successfully to version [20091115140758]
# if you want to revert your changes, use the downgrade command:
$ caribou downgrade db.sqlite . 0
downgrading db [db.sqlite] to version [0]
downgraded [db.sqlite] successfully to version [0]
Since Caribou is built to manage client side SQLite databases, it can also be run programmatically from within your application:
"""
An example illustrating how to run a migration programmatically.
"""
import caribou
db = 'db.sqlite'
migrations_dir = '/path/to/migrations/dir'
version = '20091115140758'
# upgrade to most recent version
caribou.upgrade(db, migrations_dir)
# upgrade to a specific version
caribou.upgrade(db, migrations_dir, version)
# downgrade to a specific version
caribou.downgrade(db, migrations_dir, version)
Module-Based Migrations
When bundling your app with PyInstaller, Poetry, or similar tools, filesystem-based
migration discovery may not work. You can pass a list of already-imported migration
modules directly to upgrade() and downgrade():
import caribou
from myapp.migrations import v20240101120000_create_users, v20240215090000_add_scores
modules = [v20240101120000_create_users, v20240215090000_add_scores]
# upgrade using modules
caribou.upgrade("my.db", modules)
# downgrade using modules
caribou.downgrade("my.db", modules, "0")
Migration files use a v-prefix naming convention (v20240101120000_name.py) that
is both importable as a Python module and sortable by version. The naming
convention in versions 0.5 and below (20240101120000_name.py) continues to work for directory-based discovery.
To convert existing migrations to the new convention, simply add a v prefix to the
filename (e.g. rename 20240101120000_name.py to v20240101120000_name.py).
That's it. You're rolling.
Installation
pip install caribou
Licence
Caribou is in the public domain.
Development
Things to know, before you start hacking Caribou:
Unit Tests
The unit test suite uses pytest and tox. To install and run:
uv sync
tox
Appendix
Haven't got enough?
Metadata
Release files for caribou 0.6.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 | Provenance | |
|---|---|---|---|---|
| caribou-0.6.0.tar.gz | 7.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| caribou-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.8 kB
Release files / caribou-0.6.0.tar.gz
| Download URL | caribou-0.6.0.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40b26c097017338b8c3fa18ce04421c0f7a5bb88d037fc68b1d531494d4e8cd1
|
|
BLAKE2b-256 checksum How to use checksums |
d848a096f991966905ce0a2887a89b05e03c1b4eed7f1dc9cf1502158b5d2eb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / caribou-0.6.0-py3-none-any.whl
| Download URL | caribou-0.6.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
342e51a6404efb56de620c99b9edf8afb4516e5e5aea64ecc136f5191af0a14c
|
|
BLAKE2b-256 checksum How to use checksums |
31ad11f8ecbb7b4b6aeb6d00bda81dbea13964304986eb933f312be569c09539
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for caribou 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.