Skip to main content

lx-data-types

Project description

lx-data-models

PyPI CI Docs Publish

CodeCov (Main) codecov

CodeCov (Dev) codecov

lx-dtypes provides strongly typed, Pydantic-powered data models for Lux Group medical research projects. The package ships opinionated validators, utilities for ingestion/export, and a common vocabulary so downstream services can reason about patient examinations, knowledge-base entries, and related clinical data.

Features

  • Comprehensive Pydantic models covering patient records, exam findings, and knowledge-base entities.
  • Data loaders/encoders that normalize multiple file formats into the same abstractions.
  • Utilities for working with Lux Research tooling (paths, logging, export helpers, etc.).
  • Ready-to-run pytest suite with coverage and optional type-checking.

Installation

Install the latest release from PyPI (coming soon):

pip install lx-dtypes

For contributors and power users, install with the development extras:

pip install "lx-dtypes[dev]"

Quick Start

from lx_dtypes import __version__
from lx_dtypes.models.patient import Patient

patient = Patient.model_validate({
		"id": "1234",
		"first_name": "Ada",
		"last_name": "Lovelace",
})

print(patient.full_name)
print(__version__)

Development

git clone https://github.com/wg-lux/lx-data-models
cd lx-data-models
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"

Architecture Notes

  • Treat lx-data-models as a package boundary when consumed by sibling services.
  • Import package-owned symbols through public modules where available.
  • Keep demo outputs under temp/generated_exports/; tests should use tmp_path instead of writing repository-root artifacts.
  • Do not import from lx_dtypes...tests or ...test_fixtures in consuming applications.

Migrations

The following command shortcuts are available for managing migratons, see line below for what they do:

mkmigrations

"uv run python manage.py makemigrations ${DJANGO_APP_NAME}";

migrate

"uv run python manage.py migrate";

runserver

"uv run python manage.py runserver";

resetdb

"rm -f db.sqlite3";

resetmigrations

rm -rf ${DJANGO_APP_DIR}/migrations/;
uv run python manage.py makemigrations ${DJANGO_APP_NAME};

Initialized Models

Some pydantic models with ForwardRefs require initialization before use. Import initialized models from lx_dtypes.utils.initialized_models

If you encounter this error when using a model, you may add it there.

Example for the PatientLedger model which references Examiner. This would cause a circular import, therefore we just use the Examiner model during TYPE_CHECKING in the PatientLedger model file and rebuild the model here.

from lx_dtypes.models.examiner import (
    Examiner,  # for model rebuild # type: ignore # noqa: F401
)

PatientLedger.model_rebuild()

Test & Lint

pytest
ruff check lx_dtypes tests
mypy lx_dtypes

Documentation

Install the documentation extras (included in .[dev]) and build the HTML site with Sphinx:

pip install -e ".[docs]"
make -C docs html
# open docs/_build/html/index.html in your browser

Use make -C docs linkcheck to verify outbound references before publishing to Read the Docs or GitHub Pages.

Release Process

  1. Update CHANGELOG.md and bump the version in pyproject.toml.
  2. Run formatting, linting, type-checking, and the full test suite.
  3. Build artifacts with python -m build and verify with twine check dist/*.
  4. Trigger the "Publish" GitHub workflow (either via tag/release or manual dispatch). Trusted Publisher entries for test.pypi.org and pypi.org should already reference the publish.yml workflow and the testpypi/pypi environments; approve those environments as needed and the workflow will push to TestPyPI first, then PyPI.

Easier Release Commands

lx-dtypes-release current
lx-dtypes-release prepare 0.1.2
lx-dtypes-release build
git tag v0.1.2 && git push origin v0.1.2

Easier KB Registry Commands

Register the current installed knowledge base version and data root:

lx-dtypes-kb-registry add-current /path/to/kb_registry.json --module report_template_examples

Register an explicit historical version from a provisioned path:

lx-dtypes-kb-registry add /path/to/kb_registry.json \
  --module report_template_examples \
  --version 0.1.0 \
  --input-dir /nix/store/.../site-packages/lx_dtypes/data

Contributing

See CONTRIBUTING.md for the full workflow, coding standards, and release guidelines. Bug reports and pull requests are welcome!

License

Distributed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lx_dtypes-0.1.2.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lx_dtypes-0.1.2-py3-none-any.whl (487.6 kB view details)

Uploaded Python 3

File details

Details for the file lx_dtypes-0.1.2.tar.gz.

File metadata

  • Download URL: lx_dtypes-0.1.2.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for lx_dtypes-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ba8b429483f80ac0eb3b9cd88ea3c5c062569d25d7995f51447b34759004815d
MD5 ce8e2425a64095b532c9f6be72d727c5
BLAKE2b-256 fe552df90322fc2c1ec982bcabc45a8d161129321e036e7600a06d68fa094729

See more details on using hashes here.

File details

Details for the file lx_dtypes-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lx_dtypes-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 487.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for lx_dtypes-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5523712c112d0ff63e55e27f871e567abd8f74b40a87cb066f255658d51673c8
MD5 d4c0cb3095b287dc5090b9a1ad04dc37
BLAKE2b-256 1fcdb918337b2375927310c3e158d0a3fdaf5bf6abc1e1d2a109034f58072ab9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page