Open Job Description Model for Python
raw JSON → 0.9.1 verified Fri May 01 auth: no python
Provides a Python implementation of the data model for Open Job Description (OpenJD) template schemas. Version 0.9.1 is current, with monthly releases on GitHub. The library validates and parses OpenJD job and environment templates using Pydantic.
pip install openjd-model Common errors
error ModuleNotFoundError: No module named 'openjd' ↓
cause Installing the wrong package or missing dependency 'openjd-model'.
fix
Run: pip install openjd-model
error pydantic_core._pydantic_core.PydanticCustomError: 1 validation error for JobTemplate -> steps -> 0 -> name Field required ↓
cause Missing required fields in the template YAML.
fix
Ensure all required fields like 'name' in steps are provided. Check the schema for mandatory attributes.
Warnings
breaking In version 0.9.0, field types changed from Optional[int] to Optional[int | FormatString]. Code that relies on integer types may fail type checking. ↓
fix Update type annotations to accept int | FormatString where appropriate.
breaking In version 0.8.0, DynamicConstrainedStr or FormatString creation requires a model parsing context (specification version and extensions). Instantiation without context raises an error. ↓
fix When creating these objects manually, pass the context (e.g., from a template's model_info).
deprecated The function instantiate_model is deprecated in 0.8.0; it no longer accepts optional 'loc' and 'within_field' arguments. ↓
fix Use parse function or direct model construction instead.
Imports
- JobTemplate wrong
from openjd.model.template import JobTemplatecorrectfrom openjd.model import JobTemplate - parse
from openjd.model import parse
Quickstart
from openjd.model import parse, JobTemplate
# Load from a YAML string
template_yaml = """
specificationVersion: 'jobtemplate-2023-09'
name: Example Job
steps:
- name: Step1
script:
actions:
onRun:
command: echo
args: ['{{Param.param1}}']
parameterValues:
- name: param1
type: STRING
value: hello
"""
template = parse(template_yaml, JobTemplate)
print(template.name) # Example Job