Skip to main content

A pure-Python libconfig reader/writer with permissive license

Project description

libconf is a pure-Python reader/writer for configuration files in libconfig format, which is often used in C/C++ projects. It’s interface is similar to the json module: the four main methods are load(), loads(), dump(), and dumps().

Example usage:

import libconf
>>> with open('example.cfg') as f:
...     config = libconf.load(f)
>>> config
{'capabilities': {'can-do-arrays': [3, 'yes', True],
                  'can-do-lists': (True,
                                   14880,
                                   ('sublist',),
                                   {'subgroup': 'ok'})},
 'version': 7,
 'window': {'position': {'h': 600, 'w': 800, 'x': 375, 'y': 210},
            'title': 'libconfig example'}}

>>> config['window']['title']
'libconfig example'
>>> config.window.title
'libconfig example'

>>> print(libconf.dumps({'size': [10, 15], 'flag': True}))
flag = True;
size =
[
    10,
    15
];

The data can be accessed either via indexing (['title']) or via attribute access .title.

Character encoding and escape sequences

The recommended way to use libconf is with Unicode objects (unicode on Python2, str on Python3). Input strings or streams for load() and loads() should be Unicode, as should be all strings contained in data structures passed to dump() and dumps().

In load() and loads(), escape sequences (such as \n, \r, \t, or \xNN) are decoded. Hex escapes (\xNN) are mapped to Unicode characters U+0000 through U+00FF. All other characters are passed though as-is.

In dump() and dumps(), unprintable characters below U+0080 are escaped as \n, \r, \t, \f, or \xNN sequences. Characters U+0080 and above are passed through as-is.

Comparison to other Python libconfig libraries

Pylibconfig2 is another pure-Python libconfig reader. It’s API is based on the C++ interface, instead of the Python json module. It’s licensed under GPLv3, which makes it unsuitable for use in a large number of projects.

Python-libconfig is a library that provides Python bindings for the libconfig++ C++ library. While permissively licensed (BSD), it requires a compilation step upon installation, which can be a drawback.

I wrote libconf (this library) because both of the existing libraries didn’t fit my requirements. I had a work-related project which is not open source (ruling out pylibconfig2) and I didn’t want the deployment headache of python-libconfig. Further, I enjoy writing parsers and this seemed like a nice opportunity :-)

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

libconf-1.0.0.zip (18.2 kB view details)

Uploaded Source

Built Distribution

libconf-1.0.0-py2.py3-none-any.whl (10.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file libconf-1.0.0.zip.

File metadata

  • Download URL: libconf-1.0.0.zip
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for libconf-1.0.0.zip
Algorithm Hash digest
SHA256 bbe41b6159558ca0e013ba6b4f08fffe8f0d168691a00b9836e5b06a9fc757eb
MD5 a07c6f44c75a7d8330167f46a79033a3
BLAKE2b-256 076a4e31b8f805741db44812dccb8d4d5837d2c35a47061d5ecb5920c9b59814

See more details on using hashes here.

Provenance

File details

Details for the file libconf-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for libconf-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5540121daf7223fcf45eac550623b7d3c321b3abfb166cbba978d251f1932345
MD5 e9aa978c442604530962ab18671c0402
BLAKE2b-256 f963ad20fd8cff3b67b10394110b0b3b62be3fe0a11d4a580282c42a2d38913b

See more details on using hashes here.

Provenance

Supported by

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