dina-py
Python access to the DINA API
Recommended Python and pip Versions
The features, tests, and installations were tested with Python 3.12 and pip 24.0 and are recommended for users to install. To do this, run the following commands:
sudo apt install python3
sudo apt install python3-pip
Current Features
JSON:API serialization and deserialization with Pydantic v2
Each resource exposes a Document class (e.g. CollectingEventDocument) that wraps the JSON:API envelope. The two key methods are:
Document.deserialize(response_dict)— parses an API response;nullattribute values are stripped so they are never accidentally sent back in a PATCH request.doc.serialize()— produces a request payload; only fields that were explicitly set (or mutated after deserialization) are included, using Pydantic'smodel_fields_settracking.
Safe PATCH pattern:
# GET → mutate → PATCH (only changed fields are sent)
response = api.get_entity(uuid)
doc = CollectingEventDocument.deserialize(response.json())
doc.data.attributes.dwcVerbatimElevation = "0.15" # only this field goes in the payload
api.update_entity(uuid, doc.serialize())
# To intentionally clear a field on the server, assign None after deserializing
doc.data.attributes.verbatimLatitude = None
api.update_entity(uuid, doc.serialize()) # → {"verbatimLatitude": null}
POST (create) pattern:
# Only set the fields you want — the server defaults the rest to null
doc = CollectingEventDocument(
data=CollectingEventData(
type="collecting-event",
attributes=CollectingEventAttributes(group="aafc", createdBy="dina-admin"),
)
)
api.create_entity(doc.serialize())
Currently supported schemas:
- Association
- Collecting Event
- Form Template
- Managed Attribute
- Material Sample
- Metadata
- Metagenomics Batch
- Metagenomics Batch Item
- Molecular Analysis Result
- Molecular Analysis Run
- Molecular Analysis Run Item
- Person
- Project
- Split Configuration
- Storage Unit Usage
DINA APIs
- Currently supported APIs:
- Agent API
- Person
- Collection API
- Association
- CollectingEvent
- StorageUnit
- StorageUnitUsage
- FormTemplate
- SplitConfiguration
- MaterialSample
- Organism
- Project
- Object Store API
- Any Object Store API endpoint using ObjectStoreApi's CRUD methods
- SeqDB API
- PCR Batch
- PCR Batch Item
- SEQ Reaction
- Metagenomics Batch
- Metagenomics Batch Item
- Molecular Analysis Result
- Molecular Analysis Run
- Molecular Analysis Run Item
- Export API
- Any Export API endpoint using DinaExportApi's CRUD methods
- Agent API
DINA_API_CLIENT
Currently supported operations:
upload_file:
- metavar="<file_path> : (str) = Path to the file to be uploaded.",
- help="Upload a file to Object Store. Argument: file_path"
upload_dir:
- metavar="<dir_path> : (str) = Path to the directory to be uploaded.",
- help="Upload all files in a directory to Object Store",
verbose:
- help="Verbosity of logs. Primarily for debugging.",
- action="store_true",
create_metadatas:
- metavar="<dir_path> : (str) = Path to the directory to be uploaded.",
- help="Upload all files in a directory to Object Store and create metadatas according to constants defined in ./dina-api-config.yml",
create_form_template:
- metavar="<file_path> : (str) = Path to the file to be parsed and created.",
- help="Create a form template according to specs defined in a yaml file such as ./form-template-sample.yml",
create_split_configuration:
- metavar="<file_path> : (str) = Path to the file to be parsed and created.",
- help="Create a split configuration according to specs defined in a yaml file such as ./split-configuration-sample.yml",
TEST COVERAGE
- APIs (Unit Test with Magic Mock):
- Collection API
- Collecting Event
- Managed Attributes
- Material Sample
- Organism
- Object Store API
- Metadata
- Object Export
- Agent API
- Person
- Export API
- Data Export
- Collection API
- Schemas:
- Collecting Event
- Form Template
- Managed Attribute
- Material Sample
- Metadata
- Person
- Split Configuration
- Storage Unit Usage
- Metagenomics Batch
- Metagenomics Batch Item
- Molecular Analysis Result
- Molecular Analysis Run
- Molecular Analysis Run Item
- Project
🔧 Installation & Setup
Installation
From PyPI (recommended)
# Latest stable release
pip install dinapy
# Upgrade to the latest version
pip install --upgrade dinapy
# With optional dependencies for Jupyter notebooks
pip install "dinapy[notebook]"
# With test dependencies
pip install "dinapy[test]"
# Multiple optional dependency groups
pip install "dinapy[notebook,test]"
From source (contributors / development)
# Clone the repository
git clone https://github.com/AAFC-BICoE/dina-py.git
cd dina-py
# Editable install (changes to source are reflected immediately)
pip install -e .
# Editable install with optional dependencies
pip install -e ".[notebook,test]"
Note: This package uses modern Python packaging with pyproject.toml as the single source of truth for dependencies and metadata (PEP 517/518).
Configuration
To help you configure your environment and credentials, we've provided an interactive Jupyter notebook:
👉 Installation & Setup Notebook
This notebook will guide you through:
- Entering your Keycloak credentials
- Setting up environment variables
- Saving a
.envfile for future use - Testing your connection to the DINA API
Metadata
Release files for dina-py 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 | Provenance | Actions |
|---|---|---|---|---|
| dina_py-0.2.0.tar.gz | 58.8 kB | With provenance | Details for dina_py-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dina_py-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for dina_py-0.2.0-py3-none-any.whl |
Total release size: 144.2 kB
Release files / dina_py-0.2.0.tar.gz
| Download URL | dina_py-0.2.0.tar.gz |
|---|---|
| Size | 58.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3939e5d4df9f1ce246fcddf06d0c454c1c5c3be4e579e753f006b6174cd82550
|
|
BLAKE2b-256 checksum How to use checksums |
7efe0339c81d869cdbf789a0f01ae7cc0359927cc06eaea666f166649a1771b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.
Transparency logRelease files / dina_py-0.2.0-py3-none-any.whl
| Download URL | dina_py-0.2.0-py3-none-any.whl |
|---|---|
| Size | 85.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33728e7b494f23536bc7eff7228b4334a7fa2a0a0d76e908d6a9dd62748458a5
|
|
BLAKE2b-256 checksum How to use checksums |
ef9bd0a2c8e05fcc887e3599619f11ee2f63dd04c7762eb8c02310bd670b4315
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.
Transparency logSecurity for dina-py 0.2.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for dina_py-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 1, 2026.
Transparency logA 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.