Skip to content

Flexible config string parser with key:value pairs, quoted values, ranges and validation

License

Notifications You must be signed in to change notification settings

ama228/smart-config-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmartConfigParser

A flexible Python library for parsing configuration strings with support for key:value pairs, quoted values, ranges, negation, numeric coercion, and strict validation.

Features

  • Key:Value Parsing - timeout:30 retries:3
  • Quoted Values - name:"John Doe" with escape support
  • Ranges - port:8080..9090 parsed as tuples
  • Negation - -verbose to exclude keys
  • Numeric Coercion - automatic int/float detection
  • Defaults - merge defaults with override semantics (None removes a key)
  • Strict Mode - validate against an allowlist of keys
  • Statistics - track parse calls and keys found

Installation

pip install -e .

Quick Start

from smart_config_parser import parse_config, ConfigDefaults

# Basic parsing
result = parse_config("timeout:30 retries:3 -verbose")
# {'params': {'timeout': 30, 'retries': 3}, 'excluded': {'verbose': True}, 'text': []}

# With defaults
result = parse_config("retries:5", defaults={"timeout": 30})
# {'params': {'timeout': 30, 'retries': 5}, ...}

# Ranges
result = parse_config("port:8080..9090")
# {'params': {'port': (8080, 9090)}, ...}

# Strict mode
result = parse_config("timeout:30", strict=True, allowed_keys={"timeout", "retries"})

Running Tests

pytest

About

Flexible config string parser with key:value pairs, quoted values, ranges and validation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages