Blue Core Data Models
The Blue Core Data Models are used in Blue Core API and in the Blue Core Workflows services.
🐳 Run Postgres with Docker
To run the Postgres with the Blue Core Database, run the following command from this directory:
docker run --name bluecore_db -e POSTGRES_USER=airflow -e POSTGRES_PASSWORD=airflow -v ./create-db.sql:/docker-entrypoint-initdb.d/create_database.sql -p 5432:5432 postgres:17
🛠️ Installing
- Install via pip:
pip install bluecore-models - Install via uv:
uv add bluecore-models
🗄️ Database Management
The SQLAlchemy Object Relational Mapper (ORM) is used to create the Bluecore database models.
erDiagram
ResourceBase ||--o{ Hub : "has"
ResourceBase ||--o{ Instance : "has"
ResourceBase ||--o{ Work : "has"
ResourceBase ||--o{ OtherResource : "has"
ResourceBase ||--o{ ResourceBibframeClass : "has classes"
ResourceBase ||--o{ Version : "has versions"
ResourceBase ||--o{ BibframeOtherResources : "has other resources"
Hub ||--o{ Work : "has"
Work ||--o{ Instance : "has"
BibframeClass ||--o{ ResourceBibframeClass : "classifies"
OtherResource ||--o{ BibframeOtherResources : "links to"
Works are linked to Instances by bf:instanceOf / bf:hasInstance, and to a Hub by
bf:expressionOf (see BluecoreGraph._link).
Both ends of a link need a URI. A resource created in an editor arrives without one
and is minted a Bluecore URI, but a blank node in a bulk-loaded record is an inline
description of something the record merely refers to — LC catalog data often states
bf:expressionOf against an anonymous bf:Hub — so it gets no record and no link
(see BluecoreGraph._anonymous_description).
Database Migrations with Alembic
The Alembic database migration package is used to manage database changes with the Bluecore Data models.
To create a new migration, ensure that the Postgres database is available and then run:
uv run alembic revision --autogenerate -m "{short message describing change}
A new migration script will be created in the bluecore_store_migration directory. Be sure
to add the new script to the repository with git.
Applying Migrations
To apply all of the migrations, run the following command:
uv run alembic upgrade head
🧹 Linter for Python
bluecore-models uses ruff
uv run ruff check
To auto-fix errors in both (where possible):
uv run ruff check --fix
Check formatting differences without changing files:
uv run ruff format --diff
Apply Ruff's code formatting:
uv run ruff format
🧪 Running Tests
The test suite is written using pytest and is executed via uv. All tests are located in the tests/ directory.
Run All Tests
uv run pytest
Run a specific test file
uv run pytest tests/test_models.py
Run a specific test function
uv run pytest tests/test_models.py -k test_updated_instance
Show output (prints/logs) during test execution
uv run pytest -s
💡 Make sure your virtual environment is activated and dependencies are installed with uv before running tests.
📊 Benchmarking save_graph
benchmarks/save_graph_bench.py persists a set of Bibframe graphs through the
real save path (URI minting, resource save, linking, bf-class updates) and
reports throughput (graphs/s, triples/s). With --profile it prints a cProfile
hot-spot report, which is handy for finding where the save path spends its time.
It writes to a Postgres, so first start one — the Run Postgres with Docker
command above works (it creates a bluecore database). Then point the benchmark
at it with --database-url (or the DATABASE_URL env var); the benchmark
creates the schema if it isn't there.
Run the benchmark (50 saves of the sample graphs)
uv run python benchmarks/save_graph_bench.py \
--database-url postgresql+psycopg2://airflow:airflow@localhost:5432/bluecore \
--count 50
Print a cProfile hot-spot report
Add --profile:
uv run python benchmarks/save_graph_bench.py \
--database-url postgresql+psycopg2://airflow:airflow@localhost:5432/bluecore \
--count 50 --profile
Other options:
--reset—TRUNCATEthe resource tables first (don't point this at data you care about).--input "<glob>"— RDF files to load (defaults totests/data/*.jsonld); pass a directory of.rdf/.jsonldrecords for a larger, more representative run.
💡 Since the graph content doesn't change which code runs, reusing a few sample
records many times (--count) is a fair, repeatable way to measure changes to
the save path (e.g. before/after an optimization).
⬆️ Publishing to Pypi
To publish the bluecore-models to pypi, the
following steps need to be taken.
- Update the version in
pyproject.tomleither in a feature branch PR or in a dedicated PR. - After the PR is merged, create a tagged release
using the same version (prepended with a
vi.e.v0.4.2. - Once the tagged release is saved, the Publish to PyPi Github Action should then publish the release to PyPi.
Metadata
Release files for bluecore-models 0.31.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 | |
|---|---|---|---|
| bluecore_models-0.31.0.tar.gz | 160.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bluecore_models-0.31.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 220.7 kB
Release files / bluecore_models-0.31.0.tar.gz
| Download URL | bluecore_models-0.31.0.tar.gz |
|---|---|
| Size | 160.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c35b883a0537f162bf0f4c3355fc29d648b61830d054b65e8f8ecd4f908a43e
|
|
BLAKE2b-256 checksum How to use checksums |
88067a9e9e9d571f67002762bb62886afdd9dc646492101c52fb2b53e0af6a8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","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 / bluecore_models-0.31.0-py3-none-any.whl
| Download URL | bluecore_models-0.31.0-py3-none-any.whl |
|---|---|
| Size | 60.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa28dfc511802dde18ebd2607038750e09939e8f139292c47af714723e302753
|
|
BLAKE2b-256 checksum How to use checksums |
ad964bf67a1761f256b13fa94ca731602f3a6f7753f3aa2acea4287e4860f937
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","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}
|