Skip to main content

Easily define and check configuration file structures 📂🍒

Project description

configTemplate

Build PyPI PyPI - Python Version GitHub Repo stars

Easily define configuration file structures, and check if a given configuration file matches the template.

Installation

configTemplate is tested on CPython 3.6, 3.7, 3.8, and 3.9. Simply install using pip:

pip install configTemplate

Support for additional file formats

By default, configTemplate only supports JSON configuration files, or already loaded data (not directly from a configuration file). However, using additional dependencies, configTemplate supports the following file formats:

  • JSON
  • YAML
  • TOML

To install configTemplate with the additional required dependencies to support your preferred file format, use:

pip install configTemplate[yaml]        # install dependencies for yaml files
pip install configTemplate[toml]        # toml files
pip install configTemplate[json,toml]   # json and toml files
pip install configTemplate[all]         # all available file formats

Usage

To create a template, you will need the basic Template module, and usually the other three basic modules TemplateList, TemplateDict, and Optional.

from configTemplate import Template, TemplateList, TemplateDict, Optional

Now, let's create a basic template that represents a single user:

TemplateUser = TemplateDict(            # a dictionary with 2 required values
    username=Template(str),             # username must be a string
    passcode=Template(int, str),        # can be a string or an integer.
    nickname=Optional(Template(str)),   # optional - if provided, must be a string.
)

Check if data matches your template using the check method:

errors = TemplateUser.check({'username': 'RealA10N', 'passcode': 12345})
# the check method returns a `TemplateCheckErrorManager` instance
# read full documentation for more information.

if errors:
    print(f'Found {errors.count} conflicts:')
    print(errors)   # prints a detailed and colored error list

else:
    print('data follows the template!')

Using configTemplate as a dependency

configTemplate is still under active development, and some core features may change substantially in the near future.

If you are planning to use configTemplate as a dependency for your project, we highly recommend specifying the exact version of the module you are using in the requirements.txt file or setup.py scripts.

For example, to pinpoint version v0.3.2 use the following line in your requirements.txt file:

configTemplate==0.3.2
configTemplate[yaml]==0.3.2     # If using extra file formats

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

configTemplate-0.3.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

configTemplate-0.3.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file configTemplate-0.3.2.tar.gz.

File metadata

  • Download URL: configTemplate-0.3.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.2

File hashes

Hashes for configTemplate-0.3.2.tar.gz
Algorithm Hash digest
SHA256 56c0b7ec2979666121c69f036b41c63a0a1090679a2a1a74ff335c684e9cebfb
MD5 4e98b40abdd663e0494958fdb6822f71
BLAKE2b-256 a2b85d8c97420ebae5c3e0a64b609d690b23cc3f0d62856d29248bc655f0e571

See more details on using hashes here.

File details

Details for the file configTemplate-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: configTemplate-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.2

File hashes

Hashes for configTemplate-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 41cacb4ada0f404c62e74efe88871d5c0922830b3f0df02817a9b1f1bdd87b9f
MD5 d07ffb662e31f51fe581a553a3f947a8
BLAKE2b-256 d301f6ee67db50974e857fc2e42451789785955af6f20a21ffc6b0124dea7093

See more details on using hashes here.

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