Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

A type safe dictionary in python

Project description

Build Status Coverage Status Version Status Python Versions

A type safe dictionary class in python.

LICENSE

MIT. See License File.

Install

params is on the Python Package Index (PyPI):

pip install py-params

Usage

Params instances are dict s for which default values could be provided as class level fields when subclassing Params. Those default values could than be overridden in instances of the class, by specifying the values in the constructor.

Accessing parameters not defined as class level variable would raise an AttributeError.

>>> from params import Params

>>> class TestParams(Params):
...     param_a = 'a'
...     param_b = True

>>> args=TestParams()                         ## using defaults
>>> args
{'param_a': 1, 'param_b': True}

>>> TestParams(param_a='c')                   ## override param_a
{'param_a': 'c', 'param_b': True}

>>> args.param_a = 2                          ## access as attribute or key
>>> args["param_a"] = 3
>>> args.param_a == args["param_a"]
True

>>> args.param_c
AttributeError: 'TestParams' object has no attribute 'test_c'

>>> args.param_c = 3
AttributeError: Setting unexpected parameter 'param_c' in Params instance 'TestParams'

>>> args["param_d"] = 4
AttributeError: Setting unexpected parameter 'param_d' in Params instance 'TestParams'

Resources

As an illustration of how Params could be used to reduce boilerplate code check:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for py-params, version 0.6.4
Filename, size File type Python version Upload date Hashes
Filename, size py-params-0.6.4.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page