Skip to main content

python-wax - hierarchical configuration format and context object for Python

Quick Example

>>> from wax import Wax, parse_wax
>>> w = Wax(server=Wax(host='localhost'))
>>> w.server.port = 1234

>>> print 'hostname is %(server.host)s using port %(server.port)s' % w
hostname is localhost using port 1234

>>> s = str(w)
>>> print s

[server]
host = "localhost"
port = 1234

>>> w = parse_wax(s)
print w

[server]
host = "localhost"
port = 1234

Features

  • Context objects can be serialized to / from string

  • Simple hierarchical key structure

  • Key order is maintained

  • Values can be any JSON type

  • Supports comments and annotations

Overview

Easy to construct in code:

>>> w = Wax(message='hello world', num=17)

Access values with indexes:

>>> w['num'] = 18
>>> w.message = 'hello again'
>>> w.get('missing.key', 'no problem')
'no problem'

This object translates directly to a file format. Reading the format will reconstruct the context object exactly. This allows for “round-trip” configuration that can be serialized to utf-8, edited, and read back in:

>>> w = Wax(state='New York', zip=10003)
>>> s = str(w)
>>> print s
state = "New York"
zip = 10003

>>> q = parse_wax(s)
>>> print q
state = "New York"
zip = 10003

Key order is preserved when keys are added individually. If you add them in the constructor, initial order is governed by kwargs (dict) hashing order:

>>> w = Wax(a=1, b=2, c=3)
>>> print w
a = 1
c = 3
b = 2

>>> w = Wax()
>>> w.a = 1
>>> w.b = 2
>>> w.c = 3
>>> print w
a = 1
b = 2
c = 3

Create sublevels by attaching a Wax instance to a key:

>>> w = Wax(level1=Wax(level2=Wax(property='value')))
>>> w = Wax()
>>> w.level1 = Wax()
>>> w.level1.level2 = Wax()
>>> w.level1.level2.property = 'value'

Serializing this:

>>> print w
[level1.level2]
property = "value"

Or you can set dotted keys to create nested values:

>>> w = Wax()
>>> w['foo.bar'] = 123
>>> print w.foo.bar
123

Dotted access can be used in formatting strings:

>>> w = Wax(server=Wax(host='localhost', port=1234))
>>> print 'hostname is %(server.host)s using port %(server.port)s' % w
hostname is localhost using port 1234

Metadata

Release files for python-wax 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-wax 0.3
File Size Uploaded Provenance Actions
python-wax-0.3.tar.gz 15.7 kB Without provenance Details for python-wax-0.3.tar.gz

Release files / python-wax-0.3.tar.gz

Download URL python-wax-0.3.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ced3fa933b9619d812067f6d765dda169cea9b2b54b9ca0bb64dfa1b7a99247a
BLAKE2b-256 checksum
How to use checksums
9e166e057f20dbb18b33d054809b0847aad11366aae19b9038e3945b137cb2a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for python-wax 0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page