Skip to main content

INI-files parser with schemes and types

Project description

https://travis-ci.org/zzzsochi/zini.svg?branch=master https://coveralls.io/repos/github/zzzsochi/zini/badge.svg?branch=master

INI-files parser with schemes and types

Philosophy of Zini

Application’s settings must be simple! In it should be a code or complex structures. Must be only a simple types.

Why not…

JSON?

JSON is uncomfortable and unextendable.

YAML?

The YAML is like a garden of rakes. It’s very complex format. I do not need all it’s futures.

Configparser?

  1. Configparser is ugly;

  2. Configparser is overengineered;

  3. Configparser is not have type casting;

  4. Configparser is not have type checking;

  5. Configparser is… configparser.

Supported types

boolean:

simple true or false, e.g. key = true

int:

simple numeric type, e.g. key = 13

float:

float type, e.g. key = 3.14

string:

strings always uses quotes, e.g. key = "some string"

datetime:

datetime formated like as ISO 8601

  • YYYY-MM-DD

  • YYYY-MM-DD hh:mm

  • YYYY-MM-DD hh:mm:ss

  • YYYY-MM-DD hh:mm:ss.sss

When the time, you can set timezone as Z or ±hh:mm.

E.g.:

  • key = 2005-01-13

  • key = 2005-01-13 18:00:05

  • key = 2005-01-13 15:00:05 +03:00

  • key = 2005-01-13 15:00Z

timedelta:

durations:

  • key = 20m — 20 minutes

  • key = 10h2m — 10 hours and 2 minutes

  • key = 1w2s — one week (7 days) and 2 seconds

  • key = 1s20ms — one 2 second and 20 milliseconds

  • key = 1w1d1h1m1s1ms — 694861001 milliseconds

Examples

$ cat tests/test.ini

# first comment
[first]
boolean = false
integer = 13

[second]
; second comment
boolean = true
string = "some string"

Simple reading

>>> from zini import Zini
>>> ini = Zini()
>>> result = ini.read('tests/test.ini')
>>> isinstance(result, dict)
True
>>> result['first']['boolean'] is False  # automatic type casting
True
>>> result['first']['integer'] == 13
True
>>> result['second']['string'] == "some string"
True

Types and defaults

>>> from zini import Zini
>>> ini = Zini()
>>> ini['first']['integer'] = str  # set type
>>> result = ini.read('tests/test.ini')
zini.ParseError: error in line 3: 'integer = 13'
>>> from zini import Zini
>>> ini = Zini()
>>> ini['second']['boolean'] = "string"  # set type and default value
>>> result = ini.read('tests/test.ini')
zini.ParseError: error in line 7: 'boolean = true'

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

zini-1.0.2.tar.bz2 (4.0 kB view details)

Uploaded Source

File details

Details for the file zini-1.0.2.tar.bz2.

File metadata

  • Download URL: zini-1.0.2.tar.bz2
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for zini-1.0.2.tar.bz2
Algorithm Hash digest
SHA256 c498234f692c3638a962a86523cb873d563d446ea37d4c86c1c9217d103fdcd0
MD5 6a7056f2ecc3d0ef0c623a433d21f77d
BLAKE2b-256 148d1bc2dd9e96fa3c1765e321603f50ddd046c283cca11cb2f6a69b256350fb

See more details on using hashes here.

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