Skip to main content

A powerfull lightweight library to check and variabilize your configuration files

Project description

Pyjeb

PyJeb is a powerfull lightweight library to check and variabilize your configuration files. The main features of pyjeb are:

  • Control the structure of a configuration file (missing value, type, format, valid set)
  • Add default value for missing fields
  • Setup variable values (system or user defined)
  • Allow case insensitive parameters
  • Allow to add executable functions in configuration

Get started

Steps

  1. Install PyJeb package
  2. Setup control file
  3. Setup configuration file
  4. Call control_and_setup function

Install PyJeb

Install from PyPi package manager:

pip install pyjeb

Exemple

Setup a configuration file for your script.

In this exemple a yaml file will be used, but JSON can also be used.

Exemple of yaml configuration file - configuration.yaml

HR - Employees:
  source:
    path: "/Landing/HR/Employees/$sys.timestamp('YYYY-MM-DD')"
    pattern: "*.csv"
  target:
    path: "/Bronze/HR/Employees"
HR - Managers:
  source:
    path: "/Landing/HR/Managers/$sys.timestamp('YYYY-MM-DD')"
  target:
    path: "/Bronze/HR/Managers"
HR - Payroll:
  source:
    path: "/Landing/HR/Payroll/$sys.timestamp('YYYY-MM-DD')"
  target:
    path: "/Bronze/HR/Payroll"

Setup a configuration to describe the previous configuration file and add default value for non mendatory field

Exemple of yaml configuration file - control.yaml

control = [
  { "name": "source", "type": "dict" },
  { "name": "source.path" },
  { "name": "source.pattern", "default": "*" },
  { "name": "target", "type": "dict" },
  { "name": "target.path" },
]

Load the configuration and apply function control_and_setup function with control parameters.

This function will:

  • Setup default if the value is not defined
  • Setup value of variable ($sys.timestamp in this exemple)
  • Set configuration as object (callable with dots)
import yaml
from pyjeb import control_and_setup

# load configuration file
with open("configuration.yaml") as f:
  configuration = yaml.load(f, Loader = yaml.loader.SafeLoader)

# control configuration
control = [
  { "name": "source", "type": "dict" },
  { "name": "source.path" },
  { "name": "source.pattern", "default": "*" },
  { "name": "target", "type": "dict" },
  { "name": "target.path" },
]

# loop on each item in configuration
for item in configuration:
  item_configuration = configuration[item]

  # apply the control and instantiate variables
  item_configuration = control_and_setup(item_configuration, control, to_object = True)

  # display values 
  print(f"--------------- {item}")
  print(f"source.path = '{item_configuration.source.path}'")
  print(f"source.pattern = '{item_configuration.source.pattern}'")
  print(f"target.path = '{item_configuration.target.path}'")

Output of the script

--------------- HR - Employees
source.path = '/Landing/HR/Employees/2023-12-14'
source.pattern = '*.csv'
target.path = '/Bronze/HR/Employees'
--------------- HR - Managers
source.path = '/Landing/HR/Managers/2023-12-14'
source.pattern = '*'
target.path = '/Bronze/HR/Managers'
--------------- HR - Payroll
source.path = '/Landing/HR/Payroll/2023-12-14'
source.pattern = '*'
target.path = '/Bronze/HR/Payroll'

control_and_setup function

The function control_and_setup is the only one to use in PyJeb. It use to apply controls and setup default and variables values.

See all about the structure in control_and_setup

Configuration

The configuration is a dictionary of dictionaries. Each key is a section and each section is a dictionary of key-value pairs.

Exemple:

HR - Employees:
  source:
    path: "/Landing/HR/Employees/$sys.timestamp('YYYY-MM-DD')"
    pattern: "*.csv"
  target:
    path: "/Bronze/HR/Employees"
HR - Managers:
  source:
    path: "/Landing/HR/Managers/$sys.timestamp('YYYY-MM-DD')"
  target:
    path: "/Bronze/HR/Managers"
HR - Payroll:
  source:
    path: "/Landing/HR/Payroll/$sys.timestamp('YYYY-MM-DD')"
  target:
    path: "/Bronze/HR/Payroll"

Controls

The controls are a list of dictionaries. Each dictionary is a control to apply on the configuration.

See all about the structure in controls page

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

pyjeb-1.0.5.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyjeb-1.0.5-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pyjeb-1.0.5.tar.gz.

File metadata

  • Download URL: pyjeb-1.0.5.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pyjeb-1.0.5.tar.gz
Algorithm Hash digest
SHA256 8d3b43eb92dcdeaaa6d3b149755f18825595fcd371a33f884e31b93e186e66b0
MD5 cabc5ef62b0658f372088663c4a77270
BLAKE2b-256 60089d229ca297656d52023cecf3fa5dd299fab3d56b3681f90ed82de1d82cd9

See more details on using hashes here.

File details

Details for the file pyjeb-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: pyjeb-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pyjeb-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3318b2c4d553c27f28f4096c352c94d12a2a8c65fe5c7e4a860582f399a0088f
MD5 b5125566ddd3de424d781f19c9cbcd81
BLAKE2b-256 3ddec014371630aeeb15e9307b45b1236b84df297af6538620e7797ccd2eee94

See more details on using hashes here.

Supported by

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