Ordered map parser and writer.

https://img.shields.io/github/last-commit/jfjlaros/ordered-map.svg https://github.com/jfjlaros/ordered-map/actions/workflows/python-package.yml/badge.svg https://readthedocs.org/projects/ordered-map/badge/?version=latest https://img.shields.io/github/release-date/jfjlaros/ordered-map.svg https://img.shields.io/github/release/jfjlaros/ordered-map.svg https://img.shields.io/pypi/v/ordered-map.svg https://img.shields.io/github/languages/code-size/jfjlaros/ordered-map.svg https://img.shields.io/github/languages/count/jfjlaros/ordered-map.svg https://img.shields.io/github/languages/top/jfjlaros/ordered-map.svg https://img.shields.io/github/license/jfjlaros/ordered-map.svg

This package provides:

  • A library for reading and writing ordered maps.

  • A command line interface for converting an ordered map to YAML and vice versa.

Ordered maps are used in the Arduino platform software to handle configurations made of key/value pairs stored in files with an INI like syntax.

Please see ReadTheDocs for the latest documentation.

Introduction

This package provides a library for reading and writing ordered maps and a command line interface for converting an ordered map to YAML and vice versa.

Ordered maps are used in the Arduino platform software to handle configurations made of key/value pairs stored in files with an INI like syntax.

See also

This Golang library for parsing and generating ordered maps is used in the Arduino platform software.

Installation

The software is distributed via PyPI, it can be installed with pip:

pip install ordered-map

From source

The source is hosted on GitHub, to install the latest development version, use the following commands.

git clone https://github.com/jfjlaros/ordered-map.git
cd ordered-map
pip install .

Usage

The command line interface can be used for converting an ordered map to a YAML file or vice versa. It currently has two subcommands: read and write. Use the -h option for more information.

ordered_map -h

Reading ordered maps

The read subcommand is used for reading an ordered map and converting it to YAML.

ordered_map read boards.txt boards.yml

Writing ordered maps

The write subcommand is used for reading a YAML file and converting it to an ordered map.

ordered_map write boards.yml boards.txt

Command Line Interface

Ordered map parser and writer.

usage: ordered_map [-h] [-v] {read,write} ...

Positional Arguments

subcommand

Possible choices: read, write

Named Arguments

-v

show program’s version number and exit

Sub-commands:

read

Convert an ordered map file to a YAML file.

ordered_map read [-h] INPUT OUTPUT
Positional Arguments
INPUT

input file

OUTPUT

output file

write

Convert a YAML file to an ordered map file.

ordered_map write [-h] INPUT OUTPUT
Positional Arguments
INPUT

input file

OUTPUT

output file

Copyright (c) Jeroen F.J. Laros <jlaros@fixedpoint.nl>

Library

The API library provides the read and write functions.

>>> from ordered_map import read, write

The read function reads an ordered map file string and returns a nested dictionary.

>>> data = read(open('boards.txt').read())
>>> data['FTDI_PID_6001']['vid'][0]
'0x0403'

The write function writes a nested dictionary to an ordered map file string.

>>> open('/tmp/x.txt', 'w').write(write(data))

API documentation

ordered_map.ordered_map.read(string: str)dict

Parse an ordered map file.

Parameters

string – Content of an ordered map file.

Returns

An ordered map.

ordered_map.ordered_map.write(data: dict)str

Write an odered map to a file.

Parameters

data – An ordered map.

Returns

Content of an ordered map file.

Contributors

Find out who contributed:

git shortlog -s -e