Skip to main content

human readable and writable data interchange format

Project description

https://pepy.tech/badge/nestedtext/month https://img.shields.io/readthedocs/nestedtext.svg https://github.com/KenKundert/nestedtext/actions/workflows/build.yaml/badge.svg https://coveralls.io/repos/github/KenKundert/nestedtext/badge.svg?branch=master https://img.shields.io/pypi/v/nestedtext.svg https://img.shields.io/pypi/pyversions/nestedtext.svg
Authors: Ken & Kale Kundert
Version: 3.6
Released: 2023-05-30
Documentation: nestedtext.org.
Please post all questions, suggestions, and bug reports to: Github.

NestedText is a file format for holding structured data. It is similar in concept to JSON, except that NestedText is designed to make it easy for people to enter, edit, or view the data directly. It organizes the data into a nested collection of name-value pairs, lists, and strings. The syntax is intended to be very simple and intuitive for most people.

A unique feature of this file format is that it only supports one scalar type: strings.  As such, quoting strings is unnecessary, and without quoting there is no need for escaping. While the decision to forego other types (integers, reals, dates, etc.) may seem counter productive, it leads to simpler data files and applications that are more robust.

NestedText is convenient for configuration files, address books, account information, and the like. Here is an example of a file that contains a few addresses:

# Contact information for our officers

Katheryn McDaniel:
    position: president
    address:
        > 138 Almond Street
        > Topeka, Kansas 20697
    phone:
        cell: 1-210-555-5297
        home: 1-210-555-8470
            # Katheryn prefers that we always call her on her cell phone.
    email: KateMcD@aol.com
    additional roles:
        - board member

Margaret Hodge:
    position: vice president
    address:
        > 2586 Marigold Lane
        > Topeka, Kansas 20682
    phone: 1-470-555-0398
    email: margaret.hodge@ku.edu
    additional roles:
        - new membership task force
        - accounting task force

A strength of NestedText is its lack of quoting and escaping, making it particularly nice for holding code fragments. Here is another example of NestedText that shows off this feature. It holds some Parametrize From File test cases for pytest. In this case a command line program is being tested and its response is checked using regular expressions:

-
    cmd: emborg version
    expected: emborg version: \d+\.\d+(\.\d+(\.?\w+\d+)?)?  \(\d\d\d\d-\d\d-\d\d\)
    expected_type: regex
-
    cmd: emborg --quiet list
    expected: home-\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d
    expected_type: regex
-
    cmd: emborg --quiet borg list --glob-archives "home-*" --short @repo
    expected: home-\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d
    expected_type: regex
-
    cmd: emborg --quiet files -D
    expected:
        > Archive: home-\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d
        > \d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\d\d\d\d configs/subdir/(file|)
        > \d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\d\d\d\d configs/subdir/(file|)
            # Unfortunately, we cannot check the order as they were both
            # created at the same time.
    expected_type: regex
-
    cmd: emborg due --backup-days 1 --message "{elapsed} since last {action}"
    expected: home: (\d+(\.\d)? (seconds|minutes)) since last backup\.
    expected_type: regex

One particularly attractive use-case for NestedText is command line programs whose output is meant to be consumed by either people or programs. Many programs do so by supporting a --json command-line flag that indicates the output should be computer readable rather than human readable. But, with NestedText it is not necessary to make people choose. Just output the result in NestedText and it can be read by people or computers. For example, consider a program that reads your address list and output particular fields on demand:

> address --email
Katheryn McDaniel: KateMcD@aol.com
Margaret Hodge: margaret.hodge@ku.edu

This output could be fed directly into another program that accepts NestedText as input:

> address --email | mail-to-list

Contributing

This package contains a Python reference implementation of NestedText and a test suite. Implementation in many languages is required for NestedText to catch on widely. If you like the format, please consider contributing additional implementations.

Also, please consider using NestedText for any applications you create. It is especially suitable for configuration files.

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

nestedtext-3.6.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

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

nestedtext-3.6-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file nestedtext-3.6.tar.gz.

File metadata

  • Download URL: nestedtext-3.6.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for nestedtext-3.6.tar.gz
Algorithm Hash digest
SHA256 8837596bdb5936b05ead4517713dc67f8118760ef59e58777475d4a8dd20cbac
MD5 6db909ea581aad0c485a1fa359f892cd
BLAKE2b-256 8e6f6ccfa8ac66ed2210376c3e5bbf1d92fc2bcafcacafab2fff12d8cbfcfe0c

See more details on using hashes here.

File details

Details for the file nestedtext-3.6-py3-none-any.whl.

File metadata

  • Download URL: nestedtext-3.6-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for nestedtext-3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 38ce1c072ab78f90c90398320149ef0e2a4ff58ad7900b4362735f381b0bba21
MD5 1733f6e0cdd3c1849232ae6e32f8097d
BLAKE2b-256 cab2948ca38d038be2cd924de871101d6d3575a84fe6b263c2f08c24d7d5ded0

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