Skip to main content

This library allows to load json configs and access the values like members (i.e., via dots), validate config field types and values and transform config fields.

Project description

Build Status

Overview

This library allows to load json configs and access the values like members (i.e., config.server.port instead of config['server']['port']), validate the data types of fields and transform the values of fields.

Installing

pip install git+https://github.com/janehmueller/python-json-config

Usage

from python_json_config import ConfigBuilder
from datetime import datetime

# create config parser
builder = ConfigBuilder()

# assert that port contains an int value
builder.validate_field_type('server.port', int)

# assert that the port is not a reserved port 
builder.validate_field_value('server.port', lambda port: port > 1024)

# parse a date string (e.g., Jun 1 2005) into a datetime object
builder.transform_field_value('important_date', lambda date: datetime.strptime(date, '%b %d %Y'))

# parse config
config = builder.parse_config('path/to/config.json')

# access config values
port = config.server.port
assert isinstance(port, int)
important_date = config.important_date
assert isinstance(important_date, datetime)

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

python_json_config-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

python_json_config-1.0.0-py2.py3-none-any.whl (4.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python_json_config-1.0.0.tar.gz.

File metadata

  • Download URL: python_json_config-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for python_json_config-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d78b07fe80a9a4784a1cee8a407c941381bce9d787988448c7193aafe317c216
MD5 a99093b333ba8d3798134803d8b45f4f
BLAKE2b-256 ab4469ddf31b230fe9f3ba324bf06cc42ae60ac50766f96cfd93f9fe1068faf6

See more details on using hashes here.

Provenance

File details

Details for the file python_json_config-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: python_json_config-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for python_json_config-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a85472a62944191f00a258162163535452a357835605b5327d14e3904a516321
MD5 bfae124455797830cbb3bf572b9750d6
BLAKE2b-256 2634be14b4f12e6b1fdc053b7a95b92e500baa2242dd202a11c82fba42e68c2a

See more details on using hashes here.

Provenance

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