Getting Started¶
This guide walks you through installing dcclib and performing common tasks with it.
Prerequisites¶
- Python 3.11 – 3.14
piporuv(recommended for development)
Installation¶
End-user installation¶
# Core library only
pip install dcclib
# With optional unit-aware quantities support
# (requires .NET runtime on Windows or libmono on Linux)
pip install "dcclib[quantities]"
# Install the CLI globally (recommended for command-line use)
pipx install "dcclib[cli]"
pipx install "dcclib[cli,quantities]"
Docker¶
# Run the CLI in the current directory
docker run --rm -v $(pwd):/app registry.gitlab1.ptb.de/d-ptb/dcc/dcclib/cli:latest <command>
# Run the REST API on port 8080
docker run --rm -p 8080:8080 registry.gitlab1.ptb.de/d-ptb/dcc/dcclib/rest-api:latest
Development setup¶
# Clone the repository
git clone https://gitlab1.ptb.de/d-ptb/dcc/dcclib.git
cd dcclib
# Install all packages and their dependencies
uv sync --all-packages
# Verify everything works
uv run -- pytest tests
Core library usage¶
All core objects follow the same factory-method pattern defined by the Constructible base class:
| Method | Description |
|---|---|
from_file(path) |
Load from a file path |
from_str(xml) |
Load from an XML string |
from_tree(element) |
Load from an lxml.etree.Element |
Validate a DCC¶
from dcclib.validation import XsdValidator
# Validate against schema version 3.3.0 or auto-detect from XML
validator = XsdValidator.from_version("3.3.0")
result = validator.validate_file(dcc_xml_path)
if result.is_valid:
print("Valid!")
else:
for error in result.errors:
print(f"[{error.level_name}] {error.message}")
XSD + Schematron validation¶
from dcclib.validation import SchematronValidator, XsdValidator
xsd = XsdValidator.from_version("3.3.0")
xsd_result = xsd.validate_file(dcc_xml_path)
sch = SchematronValidator.for_dcc()
sch_result = sch.validate_file(dcc_xml_path)
Convert a DCC to JSON¶
from dcclib.conversion import JSONConverter
converter = JSONConverter.from_file(dcc_xml_path)
json_str = converter.convert()
print(json_str)
Extract formulas and evaluate them¶
from dcclib.extraction.formulae import FormulaExtractor
extractor = FormulaExtractor.from_file(formula_xml_path)
formulae = extractor.extract()
for formula in formulae:
print(f"Formula: {formula.name}")
print(f" Expression: {formula.expression}")
print(f" Variables: {list(formula.variables.keys())}")
print(f" Bound vars: {list(formula.bound_variables)}")
# evaluate() uses the variable values embedded in the DCC;
# supply additional values via the dict for any remaining free symbols
if formula.variables:
results = formula.evaluate(formula.variables)
for r in results:
print(f" Result: {r.output}")
Note
Formula evaluation automatically selects unit-aware arithmetic (via dccQuantities) when
available. If dccQuantities is not installed, mpmath is used for plain numeric evaluation.
Apply an XSLT transformation¶
from dcclib.transformation import XsltProcessor
with open(xslt_path) as f:
xslt_content = f.read()
processor = XsltProcessor(xslt_content, cwd=xslt_base_dir)
result = processor.transform_file(dcc_xml_path)
print(result)
Sign and verify a DCC¶
from dcclib.signature import DCCSigner, DCCVerifier
# Sign — sign_path returns an lxml.etree.Element
signer = DCCSigner(key_pem, cert_pem)
signed_tree = signer.sign_path(dcc_xml_path)
# Verify the signed element tree
verifier = DCCVerifier(ca_cert_path)
result = verifier.verify_tree(signed_tree)
print(result.cert.subject.rfc4514_string())
Next steps¶
- Read the Architecture overview to understand how the library is structured.
- Explore the CLI reference for command-line usage.
- Browse the REST API docs to integrate
dcclibinto web services. - Dig into the API Reference for the full programmatic interface.