Skip to main content

Python package designed to help you manage and interact with text-based files in a robust and extensible way.

Project description

Config Inspector

Coverage

Overview

Config Inspector is a Python package designed to help you manage and interact with text-based config files in a robust and extensible way. It allows you to:

  • Register files for tracking and easily gather their metadata (such as size, modification time, and type).
  • Read and write files with built-in format validation for common configuration formats like INI, TOML, and JSON.
  • Update configuration files safely, merging new content with existing data where appropriate.
  • Download and extract files from remote sources, supporting ZIP and tar.gz archives.
  • Extend functionality by registering custom file updaters for new file types.

This package is useful for applications that need to manage, validate, or automate configuration and content updates across a variety of file formats.

Installation

uv pip install config-inspector

Development

To get a list of all commands with descriptions simply run make.

make env
make pip_install_editable

Testing

make pytest
make coverage
make open_coverage

Issues

If you experience any issues, please create an issue on Bitbucket.

Example Usage

from pathlib import Path
from config_inspector.manager import ConfigManager
from config_inspector.registry import FileRegistry
from config_inspector.services import FileMetadataService

class SizeFormatter:
    def format(self, size_bytes: int) -> str:
        return f"{size_bytes} bytes"

class DateTimeFormatter:
    def format(self, dt) -> str:
        # return dt.isoformat()
        return dt.strftime("%a, %b %d, %Y %-I:%M %p")

manager = ConfigManager()

config_files = [
    Path("settings.json"),
    Path("settings.toml"),
    Path("settings.ini"),
    Path("settings.cfg"),
    Path("script.bat"),
    Path("script.sh"),
    Path("script.cmd")
]

log_files = [
    Path("log.txt"),
    Path("log.log"),
]

# Register and get metadata for all files
metadata_service = FileMetadataService(size_formatter=SizeFormatter(), datetime_formatter=DateTimeFormatter())
config_registry = FileRegistry(metadata_service)
log_registry = FileRegistry(metadata_service)

for fname in config_files:
    config_registry.register(Path(fname))

for fname in log_files:
    log_registry.register(Path(fname))

metadata = config_registry.get_all_metadata()
for meta in metadata:
    print(meta)

metadata = log_registry.get_all_metadata()
for meta in metadata:
    print(meta)

# Load/Update a Config file
from config_inspector.services import FileContentService
import json

filecontent_service = FileContentService(metadata_service, max_size_bytes=50_000)
payload = filecontent_service.get_payload(Path("settings.json"), key="config")

# Inject a new key
content = json.loads(payload['config']['content'])
content['foo'] = 'bar'

# Create/update various config files
manager.update(Path("settings.json"), content)

History

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

0.1.4 (2025-12-04)

  • ADDED: tox and 100% test coverage
  • ADDED: updater_factory to get the correspinding file updater by looking at the file extension.

0.1.3 (2025-12-01)

  • ADDED: When writing a file with FileContentService.write_text() we set utf-8 errors to replace.

0.1.2 (2025-11-11)

  • ADDED: When reading a file with FileContentService.get_payload we set utf-8 errors to replace.

0.1.1 (2025-11-05)

  • ADDED: Added .js and .ps1 extensions that simply use PlainTextUpdater and do not try to validate/format on save.

0.1.0 (2025-10-06)

  • First release

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

config_inspector-0.1.4.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

config_inspector-0.1.4-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file config_inspector-0.1.4.tar.gz.

File metadata

  • Download URL: config_inspector-0.1.4.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for config_inspector-0.1.4.tar.gz
Algorithm Hash digest
SHA256 49b5429e21de68770a149bff0325be08903a4ff1a07f18e013b46393d64464c2
MD5 819d894c7c5413bd30887b05017ad7dd
BLAKE2b-256 4c22938a400cfb95b1f9465c3f40b892628eabd08594499e74b9429906789f43

See more details on using hashes here.

File details

Details for the file config_inspector-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for config_inspector-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 24ec26d29d854e26ff8ceaa1ccb6fb9ac8ee872345d7f3e0e51eb666c0b544a1
MD5 bd2f96b59b9f588e6fea9b9a5ac76780
BLAKE2b-256 e7b14469275a5972b0d900dfd5d05d0d84541eee4d338ee53a1ee88ea4722c9c

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