Skip to main content

DAN (Data Advanced Notation) Parser and Encoder for Python

Project description

DAN (Data Advanced Notation) Python Library

Python Version License

A Python implementation of the DAN (Data Advanced Notation) parser and encoder. DAN is a human-readable data format that combines the simplicity of key-value pairs with the power of nested structures and tables.

Features

  • Decode: Parse DAN text into Python dictionaries
  • Encode: Convert Python dictionaries into DAN text
  • Support for nested blocks, tables, arrays, and various data types
  • Comment support (# and //)
  • Type inference (strings, numbers, booleans, arrays)
  • Comprehensive test suite with 40+ test cases
  • Multiple real-world examples

See FEATURES.md for a complete feature list.

Installation

This repo uses uv for environments and lockfiles (uv.lock).

# Install uv: https://docs.astral.sh/uv/getting-started/installation/
uv sync

Editable install from a clone:

git clone https://github.com/marcuwynu23/dan-py.git
cd dan-py
uv sync

With dev tools (e.g. pytest):

uv sync --group dev
uv run pytest tests/

You can still install from PyPI with pip when a release is published:

pip install dan-annotation

Quick Start

Decoding DAN

from dan import decode

text = """
app {
  name: "MyApp"
  version: 1.0
  server {
    host: localhost
    port: 3000
  }
}
"""

data = decode(text)
print(data)
# {'app': {'name': 'MyApp', 'version': 1.0, 'server': {'host': 'localhost', 'port': 3000}}}

Encoding to DAN

from dan import encode

data = {
    "app": {
        "name": "MyApp",
        "version": 1.0,
        "server": {
            "host": "localhost",
            "port": 3000
        }
    }
}

text = encode(data)
print(text)

Working with Tables

text = """
users: table(id, username, email) [
  1, alice, "alice@example.com"
  2, bob, "bob@example.com"
]
"""

data = decode(text)
# {'users': [{'id': 1, 'username': 'alice', 'email': 'alice@example.com'}, ...]}

Reading from Files

from dan import decode

with open('config.dan', 'r') as f:
    config = decode(f.read())

Examples

Check out the examples/ directory for real-world usage scenarios:

  • Application configuration (config.dan)
  • Database schemas (database_schema.dan)
  • API routes (api_routes.dan)
  • Microservices configuration (microservices.dan)
  • Docker Compose (docker_compose.dan)
  • Kubernetes resources (kubernetes.dan)
  • And many more!

Running Tests

# Run all tests
python -m unittest discover tests -v

# Run specific test file
python -m unittest tests.test_dan -v

# Using pytest (if installed)
pytest tests/

Documentation

Contributing

Contributions are welcome! Please read CONTRIBUTING.md and CODE_OF_CONDUCT.md. Optional support: PayPal or the repository Sponsor button (.github/FUNDING.yml).

License

This project is licensed under the MIT License - see the LICENSE file for details.

Security

Please report security vulnerabilities to the maintainers. See SECURITY.md for more information.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dan_annotation-1.0.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dan_annotation-1.0.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file dan_annotation-1.0.0.tar.gz.

File metadata

  • Download URL: dan_annotation-1.0.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dan_annotation-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3dd7ed043a798e906a0e75fe7ea8ed3528e83052d0ac840a3c90345ae5c7f1b0
MD5 519ddf7bb1c49279e6142c6cff41933a
BLAKE2b-256 387badc3035394b99c532823dec80b762ece3f7e9e0e1f3586d854896cdd8d40

See more details on using hashes here.

File details

Details for the file dan_annotation-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dan_annotation-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dan_annotation-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad87b09ff955e7eff383d76414f8b7d3d3f0f878e764139df00fe42fadd49c0a
MD5 aea2e68750e3f03cb8135516fd39884f
BLAKE2b-256 dcad292a3f0d4818603154bcfa39523ee96da458dc6144452cafa33eb4da38cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page