Skip to main content

configPy [ 🏗 Under Construction ]

A tiny Configuration File Parser for Python Projects. Currently Supports JSON files only.

Installation

Install the Latest Stable Build using

pip install configParsePy

Usage

Use configPy to get your configurations imported to your python code from a configuration File.

Import the configPy module or its member methods to hadle different types of configuration files.

from configPy import JSONConfigParser 

JSON Configuration Files

To handle JSON Configuration Files using configPy use the JSONConfigParser object from the configPy Module.

from configPy import JSONConfigParser

Initiate the JSONConfigParser by passing the JSON configuration file as an argument.

configObject = JSONConfigParser(configFilePath="./sampleConfig.json")

Use getConfigurations() method to get the Imported Configuration. The getConfigurations() method returns the configurations as a Dictionary.

configurations = configObject.getConfigurations()

Use the configurations as a dict object.

print("Module Name: ", configurations["module_name"])
print("Purpose: ", configurations["purpose"])

Examples

from configPy import JSONConfigParser

importedConfigs = JSONConfigParser(configFilePath="./configFiles/sampleJSONConfig.json").getConfigurations()

print("Sample JSONConfigParser Test")

print("Module Name: ", importedConfigs["module_name"])
print("Purpose: ", importedConfigs["purpose"])

The whole code for the above example can be found here.

NDJSON Configuration Files

NDJSON or New-line Delimited JSON are files where each line is a valid JSON Object and each line is seperated by a newline \n character. More about NDJSON can be found here. A sample NDJSON Structure can be

{"env" : "dev" , "language" : "python" , "version" : 2.0}
{"env" : "stage" , "language" : "python" , "version" : 3.5}
{"env" : "prod" , "language" : "python" , "version" : 3.9}

Use cases for NDJSON Config Files are listed in this Issue #11

To handle NDJSON Configuration Files using configPy use the NDJSONConfigParser object from the configPy Module.

from configPy import NDJSONConfigParser

Initiate the NDJSONConfigParser by passing the configuration file as an argument.

configObject = NDJSONConfigParser(configFilePath="./sampleConfig.ndjson")

Use getConfigurations() method to get the Imported Configuration. The getConfigurations() method returns the configurations as a Dictionary.

configurations = configObject.getConfigurations()

Use the configurations as a list object with each JSON Object as a member of the list and can be accessed using the index number.

print("Dev Environment Python Version: ", importedConfigs[0]["version"])
print("Prod Environment Python Version: ", importedConfigs[2]["version"])

mapKeysNDJSON(mappingKeys=[ ])

While the getCredentials() method returns a list of JSON Objects, a user might, at times, need a key-based access to the JSON Objects (Refer to Issue #11). In such a use case the mapKeysNDJSON() provides the capability to map user-defined keys onto JSON Objects in the NDJSON Config files, that can be accessed using the key instead of index-number.

The mapKeysNDJSON() method takes an array of user defined keys, of length same as that of the number lines of JSON Objects in the NDJSON File. Each Key is mapped to the JSON Object of same index.

configObject = NDJSONConfigParser(configFilePath="./sampleNDJSONConfig.ndjson")
configurations = configObject.mapKeysNDJSON(mappingKeys=["dev","stage","prod"]).getConfigurations()

Using the getConfigurations() after using the mapKeysNDJSON([]) method returns a dict object instead of a list. The imported configurations can be used by their mapped keys.

print("Dev Environment Python Version: ", importedConfigs["dev"]["version"])
print("Stage Environment Python Version: ", importedConfigs["stage"]["version"])

Examples

from configPy import NDJSONConfigParser

importedConfigs = NDJSONConfigParser(configFilePath="./configFiles/sampleNDJSONConfig.ndjson").getConfigurations()

print("Sample NDJSONConfigParser Test")

print("Dev Environment Python Version: ", importedConfigs[0]["version"])
print("Prod Environment Python Version: ", importedConfigs[2]["version"])

importedConfigs = NDJSONConfigParser(configFilePath="./configFiles/sampleNDJSONConfig.ndjson").mapKeysNDJSON(mappingKeys=["dev","stage","prod"]).getConfigurations()

print("Sample NDJSONConfigParser with Key Mapping Test")

print("Dev Environment Python Version: ", importedConfigs["dev"]["version"])
print("Stage Environment Python Version: ", importedConfigs["stage"]["version"])


The whole code for the above example can be found here.

Metadata

Release files for configParsePy 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for configParsePy 0.1
File Size Uploaded
configParsePy-0.1.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for configParsePy 0.1
File Interpreter ABI Platform
configParsePy-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / configParsePy-0.1.tar.gz

Download URL configParsePy-0.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
906e16ab2f78e829af93a3ef5928f6cebf3e4a1d7b4577e500ff0f6c97f43423
BLAKE2b-256 checksum
How to use checksums
18c8b4464084163ab3228471829fd894c695ad0897cdd6af6ba60f8ea2a81f5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / configParsePy-0.1-py3-none-any.whl

Download URL configParsePy-0.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e18047e7df59e516fb81a32a72775ff137ad501fd5128134bf61fa0df1dafd09
BLAKE2b-256 checksum
How to use checksums
9b39cde6608a553368a50e35999e4c45ba77a41bac727244272c7be2a920e037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page