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 License Version

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 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.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

python_json_config-1.0.1-py2.py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 2 Python 3

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