Skip to main content

The boacontructor is a templating library for *data*, i.e. templating for dictionaries.

Project description

The boacontructor is a templating library for data.

It allows you to construct Python dictionaries from other templates, dictionaries or instances.

Source code is available on github:
Documentation is available here:

An Example

I’ll let the code and comments do the talking:

from boaconstructor import Template

# Some shared information in a dict. This could also be a class instance
# or something else that supports getattr and hasattr.
#
common = dict(
    timeout = 30,
    email = "admin@example.com"
)

# This is a template created in a module. You need one of these. I pass in
# references that are available at this stage. The 'host.$.name' I will pass
# in at render time.
#
webserver_data = Template('webserver',
    dict(
        interface = 'host.$.name',
        port = 32189,
        timeout = 'common.$.timeout',
        alert_email = 'common.$.email',
    ),
    # This is uses common as an 'internal' reference
    references={'common':common}
)

# At run time I can pass 'external' references to resolve the hostnames.
# Maybe I got these from a database or some other source.
#
machine_1 = webserver_data.render({'host': {'name': 'myserver1'}}),
# {'alert_email': 'admin@example.com', 'interface': 'myserver1', 'port': 32189, 'timeout': 30}

machine_2 = webserver_data.render({'host': {'name': 'myserver2'}}),
# {'alert_email': 'admin@example.com', 'interface': 'myserver2', 'port': 32189, 'timeout': 30}


# Now I can pass these to Cheetah/Mako/etc to render a specific type of
# XML/INI/Text configuration files.

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

boaconstructor-0.2.0.tar.gz (9.7 kB view details)

Uploaded Source

File details

Details for the file boaconstructor-0.2.0.tar.gz.

File metadata

File hashes

Hashes for boaconstructor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3bc9d2ad31b8aad2f768275e0d223e3fe0eff6b9a297f1efa9a39fab6e94ed12
MD5 7dc81affb331825dc42d81f800f39bf3
BLAKE2b-256 cd7b7b445642d11cefaa2f94ebf7572c0290ccaa3f8cc2eed3697c5842dc0319

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