Skip to main content

Nunavut: DSDL transpiler

nox build (main)

Build status

static analysis

Sonarcloud Quality Gate Sonarcloud bugs

unit test code coverage

Sonarcloud coverage

Python versions supported

Supported Python Versions

latest released version

PyPI Release Version

documentation

Documentation Status

license

MIT license

community/support

OpenCyphal forum

Nunavut is a source-to-source compiler (transpiler) that automatically converts OpenCyphal DSDL definitions into source code in a specified target programming language. It is constructed as a template engine that exposes a PyDSDL abstract syntax tree to Jinja2 templates allowing authors to generate code, schemas, metadata, documentation, etc.

/docs/static/images/nunavut_pipeline.svg

Nunavut DSDL transcompilation pipeline.

Nunavut ships with built-in support for some programming languages, and it can be used to generate code for other languages if custom templates (and some glue logic) are provided. Currently, the following languages are supported out of the box:

  • C11,c17,c23 (generates header-only libraries)

  • C++ (generates header-only libraries; the C++ support is currently experimental and may be removed or redesigned in the future)

  • Python (generates Python packages)

  • HTML (generates documentation pages)

Nunavut is named after the Canadian territory. We chose the name because it is a beautiful word to say and read.

Installation

Nunavut depends on PyDSDL.

Install from PIP:

pip install -U nunavut

Examples

The examples do not replace the documentation, please do endeavor to read it.

Generate C headers using the command-line tool

This example assumes that the public regulated namespace directories uavcan reside under public_regulated_data_types/. Nunavut is invoked to generate code for the former.

nnvg --target-language c --enable-serialization-asserts public_regulated_data_types/reg --lookup-dir public_regulated_data_types/uavcan

Generate HTML documentation pages using the command-line tool

See above assumptions. The below commands generate documentation for the reg namespace.

as well, because there are types in reg that will link to uavcan documentation sections.

nnvg --experimental-languages --target-language html public_regulated_data_types/reg --lookup-dir public_regulated_data_types/uavcan

Note that using the --lookup-dir option will only generate types under uavcan that are referenced by types in reg. To generate all types in both directories simply target each namespace.

nnvg --experimental-languages --target-language html public_regulated_data_types/reg public_regulated_data_types/uavcan

Generate Python packages using the command-line tool

This example assumes that the public regulated namespace directories reg and uavcan reside under public_regulated_data_types/. Nunavut is invoked to generate code for the former.

nnvg --target-language py public_regulated_data_types/reg --lookup-dir public_regulated_data_types/uavcan

Use custom templates

Partial example: generating a C struct

   /*
    * Cyphal data structure definition
    *
    * Auto-generated, do not edit.
    *
    * Source file: {{T.source_file_path.as_posix()}}
    */

    #ifndef {{T.full_name | ln.c.macrofy}}
    #define {{T.full_name | ln.c.macrofy}}

    {%- for constant in T.constants %}
    #define {{ T | ln.c.macrofy }}_{{ constant.name | ln.c.macrofy }} {{ constant | constant_value }}
    {%- endfor %}

    typedef struct
    {
        /*
            Note that we're not handling union types properly in this simplified example.
            Unions take a bit more logic to generate correctly.
        */
        {%- for field in T.fields_except_padding %}
            {{ field.data_type | declaration }} {{ field | id }}
            {%- if field.data_type is ArrayType -%}
                [{{ field.data_type.capacity }}]
            {%- endif -%};
        {%- if field is VariableLengthArrayType %}
            {{ typename_unsigned_length }} {{ field | id }}_length;
        {%- endif -%}
        {%- endfor %}
...

    } {{ T | full_reference_name }};

    #endif // {{T.full_name | ln.c.macrofy}}

More examples

Where to find more examples to get started:

  1. See built-in templates under nunavut.lang.LANGUAGE.templates.

  2. API usage examples can be found in the Pycyphal library.

Extras

Support for shell autocomplete (see argcomplete docs for full details)

pip install "nunavut[shell]"

# if you haven't setup argcomplete ever...
activate-global-python-argcomplete
source ~/.my_shell_rc_thingy_see_argcomplete_docs

# now register nnvg with argcomplete
eval "$(register-python-argcomplete nnvg)"

Bundled third-party software

Nunavut embeds the following third-party software libraries into its source (i.e. these are not dependencies and do not need to be installed):

  • Jinja2 3.1.6 by Pallets, BSD 3-clause license (with Nunavut’s auto-indent extension).

  • markupsafe 3.0.4 by Pallets, BSD 3-clause license (needed for Jinja).

Documentation

The documentation for Nunavut is hosted on readthedocs.io:

Nunavut is part of the OpenCyphal project:

Metadata

Release files for nunavut 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nunavut 3.1.1
File Size Uploaded Provenance Actions
nunavut-3.1.1.tar.gz 381.2 kB Without provenance Details for nunavut-3.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nunavut 3.1.1
File Interpreter ABI Platform Actions
nunavut-3.1.1-py3-none-any.whl Python 3 none any Details for nunavut-3.1.1-py3-none-any.whl

Total release size: 808.7 kB

Release files / nunavut-3.1.1.tar.gz

Download URL nunavut-3.1.1.tar.gz
Size 381.2 kB
Tags Source
SHA-256 checksum
How to use checksums
726c63a0427c878b835e9bc19b48b6566a3c46e5c8d2ff928c8cf58d2fcc62d1
BLAKE2b-256 checksum
How to use checksums
071c662b874e1689b507013479ddce5537052d1bb7757bc20fa13e863dc00aa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / nunavut-3.1.1-py3-none-any.whl

Download URL nunavut-3.1.1-py3-none-any.whl
Size 427.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcc1e0b08ba7ef288187bc331c08b83e9775153a9b3da7c2116062207b2a08f8
BLAKE2b-256 checksum
How to use checksums
191e5ce7ee20977ed4b29a01f8509596b5f6171914acfdef76955adda1e39abd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for nunavut 3.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page