Observed since 21 Oct, 11:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Automates CBOR serialization/deserialization for C structs
Ailuropoda is your solution! This powerful Python tool automatically generates robust C functions to encode and decode your C structs into Concise Binary Object Representation (CBOR), seamlessly integrating with the TinyCBOR library.
Ailuropoda?Manually handling CBOR for complex C data structures is a time sink. Ailuropoda eliminates this pain, letting you focus on your core logic while it handles the serialization boilerplate.
encode_MyStruct() and decode_MyStruct() functions for each struct in your C header files.CborEncoder and CborValue APIs from the TinyCBOR library.int, uint64_t, char, etc.)float, double)bool)char name[64]) as CBOR text strings.char* email, const char* notes) as CBOR text strings.cbor_generated.h and cbor_generated.c with your encode/decode functions.CMakeLists.txt file to easily compile the generated code and link against TinyCBOR.cbor2json and json2cbor conversion, simplifying data inspection and interoperability.Ailuropoda handle the rest!Ailuropoda leverages pycparser to parse your C header file's Abstract Syntax Tree (AST). It identifies struct definitions and their members, then intelligently generates the corresponding C encoding and decoding functions.
Ailuropoda is available on PyPI, making installation straightforward.
For convenient command-line usage without managing virtual environments manually, pipx is highly recommended:
pip install pipx
pipx install ailuropoda
For project-specific dependencies:
Using uv (recommended for fast dependency management):
# First, install uv (if you haven't already):
# curl -LsSf https://astral.sh/uv/install.sh | sh
# Create and synchronize the virtual environment
uv venv
uv pip install ailuropoda
# Activate the environment (optional, uv run/exec handle this)
source .venv/bin/activate
Using pip (standard installation):
python -m venv .venv
source .venv/bin/activate
pip install ailuropoda
Using pipenv:
pip install pipenv
pipenv install ailuropoda
pipenv shell
Ailuropoda provides a command-line interface ailuropoda (or ailuropoda.cbor_codegen if running via uv run directly from source).
Run the code generator:
Concrete Example:
# Generate CBOR code for tests/my_data.h into the 'generated_cbor' directory
# Using pipx:
pipx run ailuropoda tests/my_data.h --output-dir ./generated_cbor
# Using uvx:
uvx ailuropoda tests/my_data.h --output-dir ./generated_cbor
This will create a directory (e.g., generated_cbor) containing cbor_generated.h, cbor_generated.c, and a CMakeLists.txt file.
Integrate with your CMake project:
Add the generated directory to your CMakeLists.txt:
add_subdirectory(generated_cbor)
target_link_libraries(your_app PRIVATE cbor_generated tinycbor)
#include directives or macros, it's recommended to preprocess the header first (e.g., using gcc -E your_header.h) and then pass the preprocessed output to Ailuropoda.char* and other pointer types during decoding, the generated C code does not perform dynamic memory allocation (malloc). It assumes that the pointer members in your struct are already pointing to sufficiently large, allocated buffers. You are responsible for managing this memory.union types are not supported.false on any CBOR encoding/decoding error.typedef or a named member are skipped.We welcome contributions! Feel free to open issues or pull requests on our GitHub repository: jvishnefske/Ailuropoda
This project is licensed under the BSD 3-Clause License.
If you are contributing to Ailuropoda or running its tests from the source repository, follow these steps:
Navigate to your project directory and synchronize the virtual environment with core and development dependencies:
cd /path/to/Ailuropoda
uv sync --dev
Ailuropoda follows modern Python packaging and dependency management best practices, leveraging uv and pyproject.toml.
pyproject.toml (PEP 621): This file serves as the single source of truth for project metadata, dependencies, and build system configuration. It adheres to PEP 621, making the project easily discoverable and installable by tools like pip, uv, or rye.uv for Virtual Environments: uv is used for fast dependency resolution and virtual environment management. Commands like uv sync ensure all project dependencies (and development dependencies with --dev) are installed into an isolated virtual environment.uv run python <script_path> (or uv run <module_name>) to execute project scripts. This automatically activates the virtual environment and ensures the correct Python interpreter and installed packages are used. This approach eliminates the need for manual source .venv/bin/activate or manipulating the PATH environment variable, promoting a cleaner and more reliable development workflow.The project includes robust integration tests (tests/integration/test_full_pipeline.py) to ensure the entire code generation, compilation, and execution pipeline works as expected.
tmp_path: Provides a unique, temporary directory for each test, ensuring isolation and preventing test interference. All generated files (C code, build artifacts) are placed here.tinycbor_install_path: This fixture handles the compilation and installation of the TinyCBOR C library, which Ailuropoda's generated code depends on. It ensures TinyCBOR is available in a known location for subsequent compilation steps.setup_test_environment: This orchestrates the core integration steps:
ailuropoda.cbor_codegen.generate_cbor_code to generate the cbor_generated.h, cbor_generated.c, and CMakeLists.txt files into the tmp_path.subprocess to invoke cmake and make within the generated directory to compile the generated C code, linking it against the TinyCBOR library.c_test_harness_simple_data.c.jinja) that uses the generated CBOR functions, creating an executable binary.subprocess Module: Python's subprocess module is used to execute external commands, such as cmake, make, and the compiled C test binaries. This allows the Python tests to drive the C build and execution process.This setup provides a comprehensive way to validate Ailuropoda's output and its compatibility with the target C environment.
We're continuously working to improve Ailuropoda. Here are some planned features:
char* and other pointer decoding to optionally handle dynamic memory allocation (malloc/free) for decoded data, reducing the burden on the user.union types.enum types.Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.1 | 30 Jun 2025 | 2 |
This describes our collected data; it is not a security assessment.
Observed since 21 Oct, 11:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:673366699b8c9b0b99dfa3dc52fcac050c43d27c4d088535171a8bd5db87b70f