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

pip install -e .

Or install from source:

git clone https://github.com/yourusername/dan-py.git
cd dan-py
pip install -e .

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 for details on our code of conduct and the process for submitting pull requests.

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-0.1.0.tar.gz (9.8 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-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dan_annotation-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for dan_annotation-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe222e29f4154dbf3cf3d50543ccf4054f52d897093920de8ddbd69fd037f284
MD5 02f30d908977e443d5e5d3cc66249719
BLAKE2b-256 509de6a894546f44666f9d39d1a2320011262bcf77797637f9292ad18175231c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dan_annotation-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for dan_annotation-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6069c139b0b89ba8e8d7094f0200e56963583e1a0fd963570d16f9ea94a31bb
MD5 03bf555d89f171ba184fea3e134c97de
BLAKE2b-256 68fa67bfcff99f92b188f2345d61f9f5f1f87e8661754706ea443d808cff00e5

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