pyehr - a Python implementation of the openEHR® standard
pyehr (on pypi, pyehr-openehr) is an open source Python implementation of the openEHR® specification from the ground up in pure Python.
⚠️ Warning: pyehr is under active development and no stable release is available. Though some parts of the core are stable enough, both client and server are liable to change substantially.
pyehr is formed of three parts:
- core - implementation of object model of BASE, RM, AM, etc. in Python
- client - used for interacting with OpenEHR REST API servers
- server - basic Flask-based implementation of the server standard
pyehr.core
pyehr provides an implementation of the following parts of the specification which are used by both the client and the server, and many users may wish to use in a standalone manner.
Features:
- Work in the RM natively in Python with validation of invariants
text = DVText(
value="Hello, world!",
language=CodePhrase(
terminology_id=TerminologyID("ISO_639-1"),
code_string="en-gb",
preferred_term="English (United Kingdom)"
)
)
- Serialise all classes to spec-compliant JSON (with '_type' markers)
print(json.dumps(text.as_json(), indent=1))
{
"_type": "DV_TEXT",
"value": "Hello, world!",
"language": {
"_type": "CODE_PHRASE",
"terminology_id": {
"_type": "TERMINOLOGY_ID",
"value": "ISO_639-1"
},
"code_string": "en-gb",
"preferred_term": "English (United Kingdom)"
}
}
- Use methods as described in the spec across classes
from pyehr.core.rm.data_types.quantity.date_time import DVDate, DVDuration
start_date = DVDate("2026-05-07")
duration = DVDuration("P1Y2M6D")
new_date = start_date + duration
print(str(new_date))
- Validate instances in the RM against templates and archetypes (with meaningful exceptions)
with open("/path/to/file.adl14") as adl_f:
arch : Archetype = decode_adl14(adl_f.read())
with open("/path/to/instance.json") as json_f:
ev : Evaluation = decode_json(json.loads(json_f.read()))
arch.instance_valid(ev, raise_exceptions=True)
ValueError: /protocol[at0001]/items[at0002]/items[at0004]/value/value: is set to True but only [False] is valid
- Convert seamlessly between ADL v1.4 (read only) and XML and JSON versions of Archetypes
from xml.etree import ElementTree as ET
import json
from pyehr.core.its.adl14 import decode_adl14
from pyehr.core.am.aom14.archetype import Archetype
with open("/path/to/file.adl14") as adl_f:
arch : Archetype = decode_adl14(adl_f.read())
xml_version = arch.as_xml()
with open("/path/to/file.xml", "w") as xml_f:
ET.indent(xml_version)
xml_f.write(ET.tostring(xml_version, encoding="unicode"))
json_version = arch.as_json()
with open("/path/to/file.json", "w") as json_f:
json_f.write(json.dumps(json_version, indent=1))
Support level
| Specification part | Status |
|---|---|
| Base model (BASE) | ✅ Complete |
| Reference model (RM) | ✅ Complete (aside from rm.extract and rm.integration) |
| Implementation technology (ITS) - JSON | ✅ Serialisation and deserialisation complete and stable for all implemented classes |
| Archetype model (AOM v1.4 and OPT v1.4) | 🟠 Partial implementation for serialisation/deserialisation and validation, but some methods still unimplemented |
| Archetype model (ADL v1.4) | 🟠 Partial support for parsing ADL v1.4 files (aside from rules and annotations sections). Output in ADL v1.4 not supported. |
| Implementation technology (ITS) - XML | 🟠 Supported for parsing and serialising AOM v1.4 archetypes and templates, limited support elsewhere |
| Archetype model (AOM v2 or ADL v2) | ❌ Unsupported |
pyehr.client
pyehr provides both a transactional REST API client as well as a more sophisticated client for working more easily with versioned objects.
Features:
- Transactional clients for /ehr and /demographic endpoints.
from pyehr.client.ehr import OpenEHREHRRestClient, OpenEHRRestClientResponse
client = OpenEHREHRRestClient(
base_url="https://sandbox.ehrbase.org/ehrbase/rest/openehr/v1"
)
response : OpenEHRRestClientResponse = client.ehr.create_ehr()
print(response.pyehr_obj[0].as_json())
- More object-oriented client for working with versioned objects more natively
from pyehr.client.change_control import VersionedStoreClient
store = VersionedStoreClient(
base_url="http://localhost:5000"
)
p1 = ...
log.info("Create PERSON in store")
object_version_id, contribution, versioned_object = store.create(
obj=p1,
owner_id=ObjectRef("local", "EHR", GenericID("null", "null")),
committer=PartySelf(),
lifecycle_state=VersionLifecycleState.INCOMPLETE
)
pyehr.server
pyehr provides an under-development Flask-based Clinical Data Repository server with accompanying database and authentication backends.
Disclaimer
openEHR® is the registered trademark of the openEHR Foundation and is used with the permission of openEHR International. Use of the trademark does not constitute endorsement of this product by openEHR International or openEHR Foundation.
Metadata
Release files for pyehr-openehr 0.1.17
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 |
|---|---|---|---|---|
| pyehr_openehr-0.1.17.tar.gz | 749.2 kB | Without provenance | Details for pyehr_openehr-0.1.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyehr_openehr-0.1.17-py3-none-any.whl | Python 3 | none | any | Details for pyehr_openehr-0.1.17-py3-none-any.whl |
Total release size: 1.2 MB
Release files / pyehr_openehr-0.1.17.tar.gz
| Download URL | pyehr_openehr-0.1.17.tar.gz |
|---|---|
| Size | 749.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48230b7cfb542b916cb2b12a738b50a0a6942a5ca90d6bdf802121d3b1145865
|
|
BLAKE2b-256 checksum How to use checksums |
515bb975555f6a295628b231a0de1c32ef3702f5f6341e1bb1dbea0ef2a97e07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.1
|
Release files / pyehr_openehr-0.1.17-py3-none-any.whl
| Download URL | pyehr_openehr-0.1.17-py3-none-any.whl |
|---|---|
| Size | 472.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
88c0f7ee0b18b61dec1d9fd141b6fa74625ef0383e5165367f5d7989a4839a48
|
|
BLAKE2b-256 checksum How to use checksums |
fad058fbd9c96b3204e2145d1721c3c91335ca868608843f413f233f32b1a341
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.1
|
Security for pyehr-openehr 0.1.17
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.