SQLAlchemy Seeder
Project description
sqlalchemyseed
Sqlalchemy seeder that supports nested relationships.
Supported file types
- json
- yaml
- csv
Installation
Default installation
pip install sqlalchemyseed
Quickstart
main.py
from sqlalchemyseed import load_entities_from_json
from sqlalchemyseed import Seeder
from db import session
# load entities
entities = load_entities_from_json('data.json')
# Initializing Seeder
seeder = Seeder(session)
# Seeding
seeder.seed(entities)
# Committing
session.commit() # or seeder.session.commit()
data.json
{
"model": "models.Person",
"data": [
{
"name": "John March",
"age": 23
},
{
"name": "Juan Dela Cruz",
"age": 21
}
]
}
Command-line usage
Seed a database directly from data files without writing Python:
sqlalchemyseed data.json --url sqlite:///app.db
The command accepts one or more files and/or directories (a directory seeds
every .json/.yaml/.yml file inside it, in sorted order):
sqlalchemyseed seeds/ --url "$DATABASE_URL"
sqlalchemyseed a.json b.yaml --url sqlite:///app.db
The database URL may be passed with --url or the DATABASE_URL environment
variable. Model paths in the data files (e.g. models.Person) are resolved
against the current working directory, so run the command from your project
root.
Options:
--dry-run— seed inside a transaction, then roll back (validate without writing)--seeder hybrid— useHybridSeederinstead of the defaultSeeder--model models.Person— required for CSV inputs, which are not self-describing--ref-prefix— override the relationship reference prefix (default!)
The same command is available as a module:
python -m sqlalchemyseed data.json --url sqlite:///app.db
Documentation
https://sqlalchemyseed.readthedocs.io/
Found Bug?
Report here in this link: https://github.com/jedymatt/sqlalchemyseed/issues
Want to contribute?
First, Clone this repository.
This project uses uv for dependency management and running tasks.
Install dev dependencies
Inside the folder, sync the environment (uv creates the virtualenv and installs the project plus dev dependencies):
uv sync
Run tests
uv run pytest
Run the tests against a specific Python version (uv downloads it if needed):
uv run --python 3.14 pytest
Run the tests against the lowest supported dependencies (e.g. SQLAlchemy 2.0):
uv run --resolution lowest-direct pytest
Run tests with coverage:
uv run coverage run -m pytest
Autobuild documentation
sphinx-autobuild docs docs/_build/html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemyseed-2.2.0.tar.gz.
File metadata
- Download URL: sqlalchemyseed-2.2.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63e1218856e26e5e2c450f3bd47c2ba1ae63ae8817b75cf6f32414e2ace66682
|
|
| MD5 |
c7225799c8fc0acc36989d9c47a54584
|
|
| BLAKE2b-256 |
b8a7765423f78bd16445c22b72833d3dff503a988265c64f76dbd8cc0c150459
|
File details
Details for the file sqlalchemyseed-2.2.0-py3-none-any.whl.
File metadata
- Download URL: sqlalchemyseed-2.2.0-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44fddc440a52eded6cd155293064fbe4bcef6963715f378939bda406fac88744
|
|
| MD5 |
6c136ae278bc98018faf5602f2d36fe3
|
|
| BLAKE2b-256 |
33cdddc5ea2a577633940a527b463f187ba285fb4f698057f83574b987bd80c8
|