ASDF Standard Schemas
asdf-standard is a Python package that provides the schemas and specification for the Advanced Scientific Data Format (ASDF). It defines the structure and requirements for creating, editing, and reading ASDF files. The package itself primarily distributes YAML schema files; the actual Python implementation for interacting with ASDF files is provided by the separate 'asdf' library. It is currently at version 1.5.0 and releases are made as the ASDF standard evolves.
Common errors
-
ModuleNotFoundError: No module named 'asdf'
cause Attempting to import `asdf` functionality without installing the correct package. `asdf-standard` does not include the `asdf` library itself.fixInstall the `asdf` library: `pip install asdf`. -
asdf_standard.schemas.stsci.edu.asdf.core-1.6.0.yaml is not found or cannot be opened
cause Incorrect path or access method when trying to load a schema file directly from the `asdf-standard` package. The internal layout of package resources can change, or the method used to access them might be incorrect.fixUse `importlib.resources.files('asdf_standard.schemas.stsci.edu.asdf') / 'core-1.6.0.yaml'` (or similar for other schemas) to reliably locate schema files within the installed package. Ensure the schema version and filename are correct.
Warnings
- breaking Starting with `asdf-standard` version 1.5.0, Python 3.9 is no longer supported. Ensure your environment uses Python 3.10 or newer.
- breaking The URI authority for ASDF Standard schemas has changed from `stsci.edu` to `asdf-format.org` in ASDF Standard 1.5. This affects the `id` field within schema files and tag URIs.
- gotcha It is a common misconception that `asdf-standard` is the primary library for creating and reading ASDF files. `asdf-standard` provides the schema *definitions*, while the `asdf` library provides the Python *implementation* to interact with ASDF files.
Install
-
pip install asdf-standard
Imports
- files
import importlib.resources as resources # To access schema data files
Quickstart
import importlib.resources as resources
import yaml
# Asdf-standard provides schemas as data files.
# This example shows how to locate and load a core schema.
try:
# For Python 3.9+ (or importlib_resources backport)
schema_path = resources.files('asdf_standard.schemas.stsci.edu.asdf') / 'core-1.6.0.yaml'
with open(schema_path, 'r') as f:
core_schema = yaml.safe_load(f)
print("Successfully loaded core-1.6.0.yaml schema.")
except Exception as e:
print(f"Could not load schema: {e}")
print("This might happen if the path or filename is incorrect, or if `asdf` library is expected for schema access.")
# In typical usage, the 'asdf' library internally manages these schemas.
# For example, to validate an ASDF tree against schemas, you'd use the 'asdf' library:
# import asdf
# with asdf.open('my_file.asdf') as af:
# # Validation happens automatically on open and write
# pass