{"id":18471805,"url":"https://github.com/kpe/py-params","last_synced_at":"2025-07-03T22:33:28.027Z","repository":{"id":57456246,"uuid":"175906052","full_name":"kpe/py-params","owner":"kpe","description":"A type-safe dictionary class for python","archived":false,"fork":false,"pushed_at":"2021-02-05T17:30:24.000Z","size":69,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-13T19:03:39.712Z","etag":null,"topics":["arguments","config","configuration","dict","flags","parameters","python"],"latest_commit_sha":null,"homepage":"https://github.com/kpe/py-params","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kpe.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-15T23:59:18.000Z","updated_at":"2021-02-05T17:30:27.000Z","dependencies_parsed_at":"2022-09-06T10:12:57.312Z","dependency_job_id":null,"html_url":"https://github.com/kpe/py-params","commit_stats":null,"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"purl":"pkg:github/kpe/py-params","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpe%2Fpy-params","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpe%2Fpy-params/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpe%2Fpy-params/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpe%2Fpy-params/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kpe","download_url":"https://codeload.github.com/kpe/py-params/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpe%2Fpy-params/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259847044,"owners_count":22921048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arguments","config","configuration","dict","flags","parameters","python"],"created_at":"2024-11-06T10:18:03.115Z","updated_at":"2025-07-03T22:33:27.954Z","avatar_url":"https://github.com/kpe.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nParams\n======\n\n|Build Status| |Coverage Status| |Version Status| |Python Versions| |Downloads|\n\nA type safe dict utility class in python.\n\n\nLICENSE\n-------\n\nMIT. See `License File \u003chttps://github.com/kpe/py-params/blob/master/LICENSE.txt\u003e`_.\n\nInstall\n-------\n\n``params`` is on the Python Package Index (PyPI):\n\n::\n\n    pip install py-params\n\n\nUsage\n-----\n\n``Params`` represents a set of parameters modeled as a ``dict`` with a fixed set of keys.\nDefault values are provided as class level attributes in ``Params`` subclasses.\nParameter values can then be specified when constructing a ``Params`` instance overriding the default values.\nThe parameter values can then be accessed both as attributes and ``dict`` items,\nhowever the ``Params`` instance key set is closed for modification\nthus an exception is raised when a parameter name is misspelled.\n\nAccessing parameters not defined as class level attributes would raise an ``AttributeError``.\n\n.. code:: python\n\n    \u003e\u003e\u003e import params as pp\n\n    \u003e\u003e\u003e class TestParams(pp.Params):\n    ...     param_a = 1\n    ...     param_b = True\n\n    \u003e\u003e\u003e params = TestParams()                     ## using the defaults\n    \u003e\u003e\u003e params\n    {'param_a': 1, 'param_b': True}\n\n    \u003e\u003e\u003e TestParams(param_a=2)                     ## setting a value for param_a\n    {'param_a': 2, 'param_b': True}\n\n    \u003e\u003e\u003e params.param_a = 3                          ## access as attribute or key\n    \u003e\u003e\u003e params[\"param_a\"] = 4\n    \u003e\u003e\u003e params.param_a == params[\"param_a\"]\n    True\n\n    \u003e\u003e\u003e params.param_c\n    AttributeError: 'TestParams' object has no attribute 'test_c'\n\n    \u003e\u003e\u003e params.param_c = 3\n    AttributeError: Setting unexpected parameter 'param_c' in Params instance 'TestParams'\n\n    \u003e\u003e\u003e params[\"param_d\"] = 4\n    AttributeError: Setting unexpected parameter 'param_d' in Params instance 'TestParams'\n\n``Params`` instances can be used to generate CLI parser with ``argparse``:\n\n.. code:: python\n\n    \u003e\u003e\u003e import params as pp\n\n    \u003e\u003e\u003e class TestParams(pp.Params):\n    ...     number_of_things = pp.Param(None, doc=\"Specifies the number of things\", dtype=int, required=True)\n    ...     use_feature_x    = pp.Param(True, doc=\"whether to use feature X\")\n    \u003e\u003e\u003e parser = TestParams.to_argument_parser()\n    \u003e\u003e\u003e parser.print_help()\n    usage: pydevconsole.py [-h] --number-of-things NUMBER_OF_THINGS\n                           [--use-feature-x [USE_FEATURE_X]]\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      --number-of-things NUMBER_OF_THINGS\n                            Specifies the number of things\n      --use-feature-x [USE_FEATURE_X]\n                            whether to use feature X\n    \u003e\u003e\u003e args = parser.parse_known_args([\"--number-of-things\", \"7\"])\n    \u003e\u003e\u003e TestParams(args._get_kwargs())\n    {'number_of_things': 7, 'use_feature_x': True}\n\n\n.. |Build Status| image:: https://travis-ci.com/kpe/py-params.svg?branch=master\n   :target: https://travis-ci.com/kpe/py-params\n.. |Coverage Status| image:: https://coveralls.io/repos/kpe/py-params/badge.svg?branch=master\n   :target: https://coveralls.io/r/kpe/py-params\n.. |Version Status| image:: https://badge.fury.io/py/py-params.svg\n   :target: https://badge.fury.io/py/py-params\n.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/py-params.svg\n.. |Downloads| image:: https://img.shields.io/pypi/dm/py-params.svg\n\n\nNEWS\n----\n - **05.Feb.2021** - v0.10.2 - passing any ``kwargs`` to ``argparser`` ``add_argument()`` from ``Param.__init__``\n - **10.Jan.2021** - v0.10.1 - YAML (de)serialization added; support for positional argument in argparse.\n - **04.Apr.2020** - ``WithParams`` mixin added.\n - **31.Mar.2020** - support for generating ``argparse`` CLI parser. Hierarchy aggregation refactored.\n\n\nResources\n---------\n\nAs an illustration of how ``Params`` could be used to reduce boilerplate code check:\n\n- `kpe/params-flow`_  - utilities for reducing keras boilerplate code in custom layers\n- `kpe/bert-for-tf2`_ - BERT implementation using the TensorFlow 2 Keras API\n\n.. _`kpe/params-flow`: https://github.com/kpe/params-flow\n.. _`kpe/bert-for-tf2`: https://github.com/kpe/bert-for-tf2\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpe%2Fpy-params","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkpe%2Fpy-params","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpe%2Fpy-params/lists"}