Skip to main content

Python SDK for the Cascade Protocol — privacy-first health data serialization in RDF/Turtle

Project description

cascade-protocol

Python SDK for the Cascade Protocol — a privacy-first, local-first standard for serializing personal health data as RDF/Turtle.

Installation

pip install cascade-protocol

With optional extras:

pip install "cascade-protocol[pandas]"       # pandas DataFrame integration
pip install "cascade-protocol[validation]"   # SHACL validation via pyshacl
pip install "cascade-protocol[notebooks]"    # Jupyter notebook support
pip install "cascade-protocol[all]"          # Everything

Quick Start

from cascade_protocol import Medication, serialize, validate, Pod

# Create a medication record
med = Medication(
    id="urn:uuid:med0-0001-aaaa-bbbb-ccccddddeeee",
    medication_name="Metoprolol Succinate",
    is_active=True,
    dose="25mg",
    data_provenance="ClinicalGenerated",
    schema_version="1.3",
)

# Serialize to Turtle
turtle = serialize(med)
print(turtle)

# Validate structural integrity
result = validate(turtle)
print(result.is_valid, result.errors)

# Open a Cascade Pod and query records
pod = Pod.open("./my-pod")
meds = pod.query("medications")

# Convert to pandas DataFrame (requires pandas extra)
df = meds.to_dataframe()
print(df.head())

# Reconstruct models from DataFrame
restored = Medication.from_dataframe(df)

Serialization Output

@prefix cascade: <https://ns.cascadeprotocol.org/core/v1#> .
@prefix health: <https://ns.cascadeprotocol.org/health/v1#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<urn:uuid:med0-0001-aaaa-bbbb-ccccddddeeee> a health:MedicationRecord ;
    health:medicationName "Metoprolol Succinate" ;
    health:isActive true ;
    cascade:dataProvenance cascade:ClinicalGenerated ;
    cascade:schemaVersion "1.3" ;
    health:dose "25mg" .

Supported Data Types

Class RDF Type Description
Medication health:MedicationRecord Prescription and OTC drugs
Condition health:ConditionRecord Medical diagnoses
Allergy health:AllergyRecord Allergies and intolerances
LabResult health:LabResultRecord Laboratory test results
VitalSign clinical:VitalSign Vital sign measurements
Immunization health:ImmunizationRecord Vaccine records
Procedure health:ProcedureRecord Clinical procedures
FamilyHistory health:FamilyHistoryRecord Family health history
Coverage coverage:InsurancePlan Insurance coverage
PatientProfile cascade:PatientProfile Patient demographics
ActivitySnapshot health:ActivitySnapshot Daily activity data
SleepSnapshot health:SleepSnapshot Nightly sleep data

Pod API

from cascade_protocol import Pod

pod = Pod.open("./my-pod")

# Query by data type
meds = pod.query("medications")
vitals = pod.query("vital-signs")
profile = pod.query("patient-profile")

# Iterate records
for med in meds:
    print(med.medication_name, med.dose)

# DataFrame conversion
df = meds.to_dataframe()

Parsing Turtle

from cascade_protocol.deserializer import parse, parse_one

# Parse multiple records
meds = parse(turtle_string, "MedicationRecord")

# Parse a single record
med = parse_one(turtle_string, "MedicationRecord")

Namespaces

from cascade_protocol.vocabularies import NAMESPACES, CURRENT_SCHEMA_VERSION

print(NAMESPACES["cascade"])   # https://ns.cascadeprotocol.org/core/v1#
print(NAMESPACES["health"])    # https://ns.cascadeprotocol.org/health/v1#
print(CURRENT_SCHEMA_VERSION)  # 1.3

Privacy & Security

  • Zero network calls during normal operation
  • All processing is local
  • No telemetry or analytics
  • Data never leaves your machine

License

Apache 2.0 — see LICENSE.

Links

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

cascade_protocol-1.0.1.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

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

cascade_protocol-1.0.1-py3-none-any.whl (54.4 kB view details)

Uploaded Python 3

File details

Details for the file cascade_protocol-1.0.1.tar.gz.

File metadata

  • Download URL: cascade_protocol-1.0.1.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for cascade_protocol-1.0.1.tar.gz
Algorithm Hash digest
SHA256 de6eae5569e4a2401bb9868693b56709faf703b22074d74bdb4e2543d971f038
MD5 9ccadfb4862e00b7bcdef3198c1bba4a
BLAKE2b-256 5038df621e7cc16a2da402fc36fc0c2a814e72615c053211e492d1705ec2d928

See more details on using hashes here.

File details

Details for the file cascade_protocol-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cascade_protocol-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 959fddd57d8adc6f57af0ae36491a3155809584e2f37ee13345ceea7d348c58e
MD5 7f255ba7e464bf3fcec8892c268b7599
BLAKE2b-256 ab1e3027d82976b8f0b0b98a2798529ab9e29b0cd8772e70105de064ab7b2f20

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