load-xl

A library for parsing configuration files, including .env, .ini, .yaml, .json, .toml, and .xml formats.


Keywords
config, configuration, parser, env, ini, yaml, json, toml, xml, config-parser, python3
License
MIT
Install
pip install load-xl==1.0.1

Documentation

 _                    _          _
| |    ___   __ _  __| |   __  _| |
| |   / _ \ / _` |/ _` |   \ \/ / |
| |__| (_) | (_| | (_| |    >  <| |
|_____\___/ \__,_|\__,_|   /_/\_\_|

   Configuration Parser Extraordinaire

load_xl

PyPI version License: MIT Python Versions

load_xl is a versatile Python library for parsing various configuration file formats, including .env, .ini, .yaml, .json, .toml, and .xml. It provides a unified interface for loading and validating configuration data, making it easy to work with different file formats in your projects.

✨ Features

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ βš™οΈ  Multiple configuration file formats      β”‚
β”‚ πŸ”„ Automatic environment variable substition β”‚
β”‚ πŸ›‘οΈ  JSON Schema validation                   β”‚
β”‚ πŸ” File watching for auto config reloading   β”‚
β”‚ πŸ–₯️  Command-line interface (CLI)             β”‚
β”‚ 🐍 Compatible with Python 3.6+               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Installation

Install load_xl using pip:

pip install load_xl

πŸ’» Usage

As a Library

from load_xl import load_config

# Load a configuration file
config = load_config('path/to/your/config.yaml')

# Load with schema validation
schema = {...}  # Your JSON schema
config = load_config('path/to/your/config.json', schema=schema)

# Access configuration data
print(config['some_key'])

Command-line Interface

load_xl path/to/your/config.yaml --output
load_xl path/to/your/config.json --validate --schema path/to/schema.json

πŸ“ Supported File Formats

β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚.env β”‚ Environment variables         β”‚
β”‚.ini β”‚ INI configuration files       β”‚
β”‚.yamlβ”‚ YAML configuration files      β”‚
β”‚.jsonβ”‚ JSON configuration files      β”‚
β”‚.tomlβ”‚ TOML configuration files      β”‚
β”‚.xml β”‚ XML configuration files       β”‚
β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”¬ Testing

The load_xl library includes a comprehensive test suite. You can find the test script in the test directory. Here's a snippet of the test.py file:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from load_xl import load_config, FileParsingError

# Test .env file parsing and loading
try:
    print("\n[+] Loading .env file...")
    env_config = load_config(".env")
    print(env_config.get("TEST"))
    print(env_config.get("TEST_ENV"))
except FileParsingError as e:
    print(f"Error in parsing .env file: {e}")

# ... (tests for other file formats)

# Test .xml file parsing and returning as dict
try:
    print("\n[+] Loading .xml file...")
    xml_config = load_config("test.xml")
    print(xml_config)
except FileParsingError as e:
    print(f"Error in parsing .xml file: {e}")

To run the tests, navigate to the test directory and execute:

python test.py

πŸ”§ Advanced Features

Environment Variable Substitution

load_xl automatically replaces ${VAR} patterns in your configuration files with the corresponding environment variable values.

File Watching

from load_xl import ConfigFileWatcher, YamlFileParser

watcher = ConfigFileWatcher('config.yaml', YamlFileParser)
watcher.start()

# Your application logic here

watcher.stop()

Note: There are example schema files provided in schemas folder.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

πŸ™ Acknowledgments

  • Thanks to all contributors and users of load_xl
  • Inspired by the need for a unified configuration parsing solution
  • This project was developed with some assistance from ChatGPT 4.0 , showcasing the potential of AI-assisted coding and for my peronal experience too

For more information and updates, please visit the GitHub repository.

 ______________________________
< Thank you for using load_xl! >
 ------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||