Dynamic Attributable Config System
Project description
GOFIGURE
*Only PyYAML for YAML support
A dynamic configuration system with flexible access patterns for Python. Zero external dependencies except PyYAML.
✨ Features
- 🔄 Dual Access Patterns: Use both
config.keyandconfig['key']interchangeably - 💾 File Persistence: Automatic loading/saving with JSON and YAML support
- 🌳 Smart Nesting: Automatic handling of nested dictionaries with autovivification
- 🛡️ Namespace Protection: Intelligent method naming when your data conflicts
- ⚡ Autosave: Optional automatic persistence on configuration changes
- 🔒 Type Safe: Full typing support with comprehensive error handling
- 🎯 Zero Config: Works out of the box with sensible defaults
🚀 Quick Start
from gofigure import Gofig
# Load from file
config = Gofig.FromJSON('config.json')
# Dual access patterns
config.database.host = 'localhost' # Attribute access
config['database']['port'] = 5432 # Dict access
# Automatic nesting (autovivification)
config.api.endpoints.users = '/api/v1/users'
print(config.api.endpoints.users) # /api/v1/users
# Save changes
config.save()
# Autosave mode - changes persist immediately
config = Gofig.FromYAML('settings.yaml', autosave=True)
config.debug = True # Automatically saved!
📦 Installation
pip install gofigure
🔧 Advanced Usage
Autovivification Control
# Default: auto-create nested structures
config = Gofig(autovivify=True)
config.new.nested.key = "value" # Creates nested structure automatically
# Strict mode: only access existing keys
config = Gofig(autovivify=False, nullaccess=AttributeError)
config.nonexistent # Raises AttributeError
# Return None for missing keys
config = Gofig(autovivify=False, nullaccess=None)
print(config.missing) # None
Namespace Conflict Resolution
# Automatic resolution
config = Gofig({'save': 'important_data'})
config.Save() # Uses 'Save' instead of 'save'
# Standalone functions (always available)
from gofigure import save, reload
save(config)
reload(config)
# Extreme conflicts - use operators
config = Gofig({
'save': 'data', 'Save': 'data', 'persist': 'data'
}, manglenamespace=True)
config >> ... # Save via operator
config << ... # Reload via operator
Flexible Initialization
# Hierarchy: file → data → overrides
config = Gofig(
data={'defaults': True},
filepath='config.json',
autosave=True,
environment='production', # Override
debug=False # Override
)
Error Handling
from gofigure import UnsupportedFormat, NamespaceConflict
try:
config = Gofig.FromJSON('config.xml') # Wrong format
except UnsupportedFormat as e:
print(f"Format not supported: {e.fmt}")
print(f"Supported formats: {e.supported}")
📋 Supported Formats
| Format | Extensions | Status |
|---|---|---|
| JSON | .json |
✅ Full support |
| YAML | .yaml, .yml |
✅ Full support |
| TOML | .toml |
🚧 Coming soon |
🔬 Technical Features
- Smart Merging: Nested configurations merge intelligently
- Memory Efficient: Shared root references for nested objects
- Type Hints: Full typing support with generics
- Comprehensive Tests: 101 tests covering edge cases
- No Magic: Clear, predictable behavior
📝 Requirements
- Python 3.9+
- PyYAML 6.0+ (for YAML support)
📄 License
MIT License - see LICENSE file for details.
Built with ❤️ and zero unnecessary dependencies
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gofigure-0.2.5.tar.gz
(19.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gofigure-0.2.5.tar.gz.
File metadata
- Download URL: gofigure-0.2.5.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4c7cccede1fb49ef25b19542ecbe6c123c04847d900f449a66db89eaa321857
|
|
| MD5 |
5f03924f053b6ee3a9e804d3c50519c2
|
|
| BLAKE2b-256 |
8b34bbdd2048e1ed56a32319c7a30b096b2f2a317b866c65f81d131c1ba729f4
|
File details
Details for the file gofigure-0.2.5-py3-none-any.whl.
File metadata
- Download URL: gofigure-0.2.5-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d034fd35e528a47b31c0ea659f1d40160d7bf60640249f5f0ec7d317dd0dc56e
|
|
| MD5 |
47f0622606da99b68c7bbc823efdb091
|
|
| BLAKE2b-256 |
050f22303677b675a2a8f540f3c8986545143bfc45a6493a572fdb0c423c9548
|