Skip to main content

Library to use .json files as configuration objects using namedtuple.

Project description

Library to use .json files as configuration objects using namedtuple.

This library let’s you use .json files as “objects” within your code.

Installation

pip install git+https://github.com/yeyeto2788/Utils-Config

Usage

Create a file called config.json (you can change the name to something you like) and add some content to it.

In this demo we add the following data.

{
  "temperature": 30,
  "screen": {
    "width": 640,
    "height": 480
  },
  "name": null,
  "id": "4V3RYCR4ZY1D"
}

Now let’s head over Python and test the module and its functions.

Importing the module and loading our .json file.

import utils_config
config_file="./config.json"
config = utils_config.load_config(config_file)

Now let’s see what we’ve got in the config variable, serializing it into a dictionary.

utils_config.serialize_config(config)

Let’s access to its keys/attributes.

config.temperature
config.screen.width
config.name
config.id

Edit the current configuration (Take into account that this function will return a new configuration namedtuple)

config = utils_config.edit_config(config, {"id": "another_id"})
config.id

Save the configuration to a file.

utils_config.save_config(config_file, config)

Contributing

All contributions, pull requests and comments are welcome!

When contributing it is important to test the module in order to make sure everything is working as expected. For that install dependencies to run the tests.

pip install pytest pytest-cov mock pylint

Running tests and see coverage.

py.test --cov -v --cov-config=.coveragerc --cov-report=html

This will generate a report with the coverage which is at 100% now, let’s try to keep it at the same percentage.

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

Utils-Config-1.0.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

Utils_Config-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file Utils-Config-1.0.0.tar.gz.

File metadata

  • Download URL: Utils-Config-1.0.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.9

File hashes

Hashes for Utils-Config-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ab3f2caae0d3ad2f2cf2e261c1117be0bec3f1d7a2e924f85ee024f74e6e995b
MD5 59333b721ef4b9f392485e80ee9ba89f
BLAKE2b-256 60ae57eb29a546c7c0a1b612404e296f9321cd0e81f8c28f2f9315daa46c50a8

See more details on using hashes here.

File details

Details for the file Utils_Config-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: Utils_Config-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.9

File hashes

Hashes for Utils_Config-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49c8573018ba387d40f45df42d0a8fabfccd59aecda86f74ba46662fdb60dcce
MD5 81eddfdf37e892eb695293a7823f62e0
BLAKE2b-256 0865a2597196c00724c3db81a24e326d74560196b55d5b797c5bc0ff72609aa6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page