C++ bindings for the Advanced Scientific Data Format (ASDF) using pybind11.
ASDF-Pybind provides C++ bindings to the Python implementation of the Advanced Scientific Data Format (ASDF). It allows C++ applications to read and write ASDF files by leveraging the robust Python implementation through pybind11.
The Advanced Scientific Data Format (ASDF) is a next-generation interchange format for scientific data, built on YAML for human-readable headers and binary data blocks for efficient storage of numerical arrays.
- Read and write ASDF files from C++
- Access and modify ASDF tree structures
- Control array compression and storage options
- Schema validation
- History entry tracking
- Support for different ASDF standard versions
Before building ASDF-Pybind, install the required dependencies:
# Install Python dependencies
pip install pybind11 asdf numpy
# Install system dependencies (Ubuntu/Debian)
sudo apt-get install cmake build-essentialmkdir build
cd build
cmake ..
makeFor building with examples:
mkdir build
cd build
cmake .. -DBUILD_EXAMPLES=ON
makeTo install ASDF-Pybind system-wide:
mkdir build
cd build
cmake ..
make
sudo make installYou can customize the installation directory using the CMAKE_INSTALL_PREFIX variable:
cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/installASDF-Pybind follows Semantic Versioning. The current version can be found in the CMakeLists.txt file.
#include <iostream>
#include <string>
#include <map>
#include <asdf_wrapper.h>
// Initialize Python interpreter (required when embedding Python)
py::scoped_interpreter guard{};
// Create a new ASDF file with data
std::map<std::string, std::any> tree;
tree["foo"] = 42;
tree["bar"] = std::string("hello world");
tree["baz"] = 3.14159;
// Create AsdfFile object and write to file
AsdfFile asdf(tree);
asdf.write("example.asdf");
// Read from file
AsdfFile reader("example.asdf");
reader.info(); // Display file contents
// Modify and write to new file
reader.addHistoryEntry("Modified by C++ application",
{{"name", "my-app"}, {"version", "1.0.0"}});
reader.write("modified.asdf");See the examples directory for more detailed examples.
When using asdf-pybind in your C++ projects after installing via pip, you need to:
- Include the header file:
#include "asdf_wrapper.h"(found in theinclude/directory) - Link against Python and pybind11
cmake_minimum_required(VERSION 3.12)
project(my_asdf_project)
# Find Python and pybind11
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 REQUIRED)
find_package(asdf_pybind REQUIRED)
# Create your executable
add_executable(my_program main.cpp)
# Link libraries
target_link_libraries(my_program PRIVATE
asdf_pybind::asdf_pybind
pybind11::embed
)The documentation for ASDF-Pybind is built using Sphinx and hosted on GitHub Pages:
To build the documentation locally:
cd docs
pip install sphinx sphinx_rtd_theme
make htmlThe generated documentation will be available in docs/_build/html.
To build the documentation:
mkdir build
cd build
cmake .. -DBUILD_DOCS=ON
make docsThe generated documentation will be in build/docs/build/.
ASDF-Pybind uses C++ tests with Google Test framework to ensure the functionality of the library. To run the tests:
mkdir build
cd build
cmake .. -DBUILD_TESTING=ON
make
ctestOr run the test executable directly:
./build/bin/test_asdf_wrapperNote: While ASDF-Pybind uses Python libraries internally through pybind11, it is designed as a C++ library and all testing is done through C++ interfaces.
ASDF-Pybind is licensed under the MIT License. However, it binds to the ASDF Python package which is licensed under the BSD 3-Clause License. The LICENSE file contains both licenses for clarity.
When using this library, you must comply with both:
- The MIT License for the binding code
- The BSD 3-Clause License for the underlying ASDF library functionality
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests to ensure they pass
- Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code style
- Write tests for new features
- Update documentation as needed
- Update the CHANGELOG.md file
For maintainers, to create a new release:
- Update the version in CMakeLists.txt
- Update CHANGELOG.md with the new version and release notes
- Create a git tag for the version
- Push the tag to GitHub
- Create a GitHub release using the tag
- This will automatically trigger the documentation build and deployment to GitHub Pages
- Documentation will be available at
https://davetbarr.github.io/asdf-pybind/vX.Y.Z/where X.Y.Z is the version number
- The ASDF team for creating the Python implementation
- The pybind11 team for the excellent C++/Python binding library