Registry / serialization / asdf

asdf

JSON →
library5.2.0pypypi✓ verified 35d ago

Python implementation of the ASDF Standard, a language-agnostic serialization format for scientific data. It handles serialization of Python objects (including NumPy arrays, Astropy objects, and custom types) into ASDF files, which are YAML-based with support for binary data. The library is actively developed with several releases per year, and the current version is 5.2.0.

serializationdata
Install & Compatibility
Where this runs
tested against v5.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
4/8 runs
✓ 6.29s
py 3.11
4/8 runs
✓ 5.75s
py 3.12
4/8 runs
✓ 4.91s
py 3.13
4/8 runs
✓ 5.11s
py 3.9
4/8 runs
✓ 7.55s
109MB installed
● package 109MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

While technically correct, the top-level import is preferred and canonical.

from asdf import AsdfFile
import asdf; asdf.open(...)

This quickstart demonstrates how to create a simple ASDF data structure, write it to a file, and then read the data back. It uses a dictionary for the tree structure and includes a NumPy array, a common use case for ASDF.

import asdf import numpy as np import os # Create some data tree = { 'scientific_name': 'M42', 'coordinates': { 'ra': 83.822083, 'dec': -5.391111 }, 'data': np.array([[1, 2], [3, 4]], dtype=np.int64) } # Create an ASDF file object ff = asdf.AsdfFile(tree) # Define file path file_path = "example.asdf" # Write the file ff.write_to(file_path) print(f"ASDF file written to {file_path}") # Read the file back with asdf.open(file_path) as af: print(f"Read data:\n{af.tree['data']}") print(f"Read coordinates: {af.tree['coordinates']}") # Clean up the created file os.remove(file_path)
asdf --version
Debug
Known footguns
breakingThe `AsdfFile.tree` attribute is now read-only. Direct assignment like `ff.tree = new_tree` will raise an `AttributeError` in `asdf` 5.0 and later.
breakingMinimum Python version increased to 3.10. Users on older Python versions will encounter `ImportError` or environment resolution issues.
breakingThe `AsdfFile.open()` function no longer supports `mode='r+'` for read-write operations. Using it will raise a `ValueError` in `asdf` 4.0 and later.
gotchaCustom Python types require explicit registration with ASDF. Without proper registration (via an `Extension`, `Tag`, and `Converter`), ASDF may not be able to serialize/deserialize them correctly, often leading to `ValidationError` or loss of type information.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
19 hits · last 30 days
gptbot
4
ahrefsbot
4
bytedance
4
script
1
Resources