GithubHelp home page GithubHelp logo

ssweeny / python-libconf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrisaichinger/python-libconf

0.0 2.0 0.0 36 KB

Pure-Python libconfig file reader/writer with permissive licensing

License: MIT License

Python 100.00%

python-libconf's Introduction

libconf

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 io, libconf
>>> with io.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 :-)

Release notes

  • 1.0.1, released on 2017-01-06
    • Drastically improve performance when reading larger files
    • Several smaller improvements and fixes
  • 1.0.0, released on 2016-10-26:
    • Add the ability to write libconf files (dump() and dumps(), thanks clarkli86 and eatsan)
    • Several smaller improvements and fixes
  • 0.9.2, released on 2016-09-09:
    • Fix compatibility with Python versions older than 2.7.6 (thanks AnandTella)

python-libconf's People

Contributors

anandtella avatar chrisaichinger avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.