Skip to main content

kvProcessor

PYPI Package • GitHub
A Python package for processing and validating configuration dictionaries against a custom .kv file format.

Installation

Install via pip:

pip install kvprocessor

File format

The .kv file format is a simple key-value configuration format with support for type validation and default values. Each line in a .kv file follows this syntax:

VARIABLENAME<TYPE>:DEFAULTVALUE
  • VARIABLENAME: The name of the variable.
  • TYPE: The expected type(s) of the variable. Multiple types can be separated by |.
  • DEFAULTVALUE: The default value for the variable. Use none if no default value is provided.
  • Comments: Both comments as a new line, or inline are supprorted, with the # character.

Example .kv file:

DATABASE_NAME<string>:none
DATABASE_PORT<int>:3306
ENABLE_LOGGING<bool>:true
MAX_CONNECTIONS<int|none>:none

KV Manifests

A KV manifest is a file that defines namespaces and their relationships. It is used to organize and manage configurations across multiple .kv files. Each line in a manifest file follows this syntax:

namespace1:namespace2
  • namespace1: The namespace that dosent exist as a file, but has the value as namespace2.
  • namespace2: The full namespace path

Example manifest file:

# A valid manifest
root:database
root:logging
database:connection

Validating a manifest:

You can validate a manifest using the KVManifestLoader:

from kvprocessor.kvmanifestloader import KVManifestLoader

manifest_path = "test/manifest.txt"
loader = KVManifestLoader(manifest_path)
loader.validate_manifest()  # Validates the manifest structure

Config.json

The config.json file is used by the KVStructLoader to define the structure and metadata of the configuration. It includes details such as the version, root namespace, and manifest file.

Example config.json:

Note: This example uses features from 0.1.10, the current version is 0.2.14+. Some extra parameters may be needed.

{
    "version": "0.1.10",
    "root": "root",
    "manifest": "manifest.txt",
    "platform": "github",
    "owner": "Voxa-Communications",
    "repo": "VoxaCommunicaitons-Structures",
    "branch": "main"
}

Using KVStructLoader with config.json:

from kvprocessor import KVStructLoader

kv_config_url = "https://github.com/Voxa-Communications/VoxaCommunicaitons-Structures/raw/refs/heads/main/struct/config.json"
kv_struct_loader = KVStructLoader(kv_config_url)
kv_processor = kv_struct_loader.from_namespace("root.database.connection")

Usage

KVProcessor

from kvprocessor import KVProcessor
from kvprocessor.kvenvloader import load_env

kv_file_path = "test/test.kv"  # Directory to .kv file
kv_processor = KVProcessor(kv_file_path)  # Create a KV processor class
kv_keys = kv_processor.return_names()  # Gets the keys (VARIBLENAME) from the .kv file
env_list = load_env(kv_keys)  # Loads all the ENV variables that match those keys
validated_config = kv_processor.process_config(env_list)  # Verifies that those env variables exist and are of the correct type
print(validated_config)

KVStructLoader

from kvprocessor import KVStructLoader

kv_config_url = "https://github.com/Voxa-Communications/VoxaCommunicaitons-Structures/raw/refs/heads/main/struct/config.json"
kv_struct_loader = KVStructLoader(kv_config_url)
kv_processor = kv_struct_loader.from_namespace("root.database.connection")
user_settings = {
    "DATABASE_NAME": "test_db",
    "DATABASE_PORT": 5432,
}
validated_config = kv_processor.process_config(user_settings)
print(validated_config)

KVFileMerger

from kvprocessor import KVFileMerger

file1 = "test/file1.kv"
file2 = "test/file2.kv"
merger = KVFileMerger(file1, file2)
merged_file = merger.merge("merged.kv")  # Merges two KV files into a new file
print(f"Merged file created at: {merged_file}")

KVFileUtils

from kvprocessor.kvfileutils import search_kv_files, copy_kv_file, delete_kv_file

# Search for KV files in a directory
kv_files = search_kv_files("test")
print(f"Found KV files: {kv_files}")

# Copy a KV file
copy_kv_file("test/test.kv", "test/copy_test.kv")
print("KV file copied.")

# Delete a KV file
delete_kv_file("test/copy_test.kv")
print("KV file deleted.")

KVFileDiffChecker

from kvprocessor import KVFileDiffChecker

file1 = "test/file1.kv"
file2 = "test/file2.kv"
diff_checker = KVFileDiffChecker(file1, file2)
differences = diff_checker.diff()
print(f"Differences between files: {differences}")

KVValidator

from kvprocessor import validate_kv_file

kv_file_path = "test/test.kv"
is_valid = validate_kv_file(kv_file_path)
print(f"KV file is valid: {is_valid}")

Additional Data Types

The library supports additional data types such as datetime, date, time, and decimal. These can be used in .kv files as follows:

EVENT_DATE<datetime>:none
PRICE<decimal>:none

Example usage:

from kvprocessor import KVProcessor

kv_file_path = "test/test.kv"  # Path to your .kv file
kv_processor = KVProcessor(kv_file_path)

# Example configuration with additional data types
config = {
    "EVENT_DATE": "2025-05-01T12:00:00",
    "PRICE": "19.99",
}

validated_config = kv_processor.process_config(config)
print(validated_config)

Building

For building the library locally
Requires: python3.8+, pip, linux system (if using the predefined shell files)

  1. git clone https://github.com/connor33341/kvProcessor.git
  2. cd kvProcessor
  3. bash build.sh

build.sh will also install kvProcessor as a local package, which you will be able to use. If you add new features to your fork and would like them to be featured on the main repo, submit a Pull Request.

CLI

At the current moment, there exists no documentation on this. If you would like to find usage, visit the file kvprocessor\cli.py.

Basic Usage:

python kvprocessor/cli.py --version

Library Modules

For a complete list, visit kvprocessor\__init__.py. A breif list of main modules, will be listed here.

  • kvprocessor.kvprocessor, Exports: KVProcessor
  • kvprocessor.kvstructloader, Exports: KVStructLoader
  • kvprocessor.kvmanifestloader, Exports: KVManifestLoader

For the nerds

The syntax was already mentioned, however, if you would like to see how it parses, the following regex is used to determine the: name, type, and default:

(\w+)<([\w\|]+)>:([\w+]+|none)

With this knowledge, you probably can figure out a way to write .kv files in a weird way, out of typical standard.

Metadata

Release files for kvprocessor 0.2.14

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

Source distribution (sdist)

Source distribution for kvprocessor 0.2.14
File Size Uploaded
kvprocessor-0.2.14.tar.gz 19.0 kB Details

Built distribution (wheel)

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

Total release size: 39.5 kB

Release files / kvprocessor-0.2.14.tar.gz

Download URL kvprocessor-0.2.14.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a3f5f7955ad630f03001c789b125e66d8da3c5afcf2c9956e4fa1a9285eac032
BLAKE2b-256 checksum
How to use checksums
0cafbbc35f25fc7aaa0b755aa86b4559c4bc0838840aa8a6ce6c0e73da7429ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / kvprocessor-0.2.14-py3-none-any.whl

Download URL kvprocessor-0.2.14-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30e436a6adb690879bbd67176c47c2a667684746df35fe00c2db9f47c2aac69c
BLAKE2b-256 checksum
How to use checksums
fce4b0ba4aaa632afd995eaf5c9acbae4574c208c20e714a67285d1aa0f7d189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.2.14 This release

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.2

2 release files

0.1.0

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