Pythils
A Python utilities package.
Installation
pip install pythils
Configuration Management
The pythils.config module provides tools for managing hierarchical configuration with advanced features.
Features
- ConfigDict: A dictionary-like object with nested key support
- ConfigRef: References to other configuration values
- Wildcard Configuration: Support for default values with
*and.wildcards - Multiple Sources: Load configuration from environment variables, files (JSON, YAML, Python)
- Nested Access: Navigate through configuration hierarchies
Usage Examples
from pythils.config import ConfigDict, ConfigRef
# Create a configuration
config = ConfigDict({
'app': {
'name': 'My App',
'version': '1.0.0'
},
'database': {
'host': 'localhost',
'port': 5432
},
# Reference another configuration value
'app_id': ConfigRef('app.name'),
'features': {
# Provide defaults with wildcards
'*': {
'enabled': True
},
'api': {
'.': ConfigRef('app'), # Default with . wildcard
'name': 'My App API', # Override default from . wildcard
'base_url': 'https://example.com/api/'
},
'webui': {
'enabled': False # Override default from * wildcard
}
}
})
# Access configuration values
print(config.get('app.name')) # My App
print(config.get('database.port')) # 5432
print(config.get('app_id')) # My App (resolved reference)
print(config.get('features.api.enabled')) # True (from wildcard)
print(config.get('features.api.version')) # '1.0.0' (from dot-wildcard)
# Nested configuration access
db_config = config['database']
print(db_config.get('host')) # localhost
print(db_config.get('..app.name')) # My App (parent/root navigation)
# Configuration references
config = ConfigDict({
'base_url': 'https://api.example.com',
'endpoints': {
'users': ConfigRef('base_url') + '/users',
'auth': ConfigRef('.users') + '/auth' # relative reference
}
})
print(config.get('endpoints.auth')) # https://api.example.com/users/auth
# Load from environment variables
env_config = ConfigDict.from_env('MYAPP_')
# Load from file
file_config = ConfigDict.from_file('config.json')
Dynamic Interfaces
The pythils.interface module provides tools for creating interfaces with multiple implementations that can be dynamically loaded.
Features
- DynamicInterface: Abstract base class for creating interfaces
- Implementation Discovery: Automatically discover and load implementations
- Configuration-based Instantiation: Create instances of implementations from configuration dictionaries
- Flexible Selection: Choose implementations by name or from configuration
Usage Examples
from pythils.interface import DynamicInterface
# Define an interface
class Database(DynamicInterface):
__implementation_package__ = "myapp.db.implementations"
__default_implementation__ = "postgres"
def connect(self):
"""Connect to the database"""
pass
def query(self, sql):
"""Execute a query"""
pass
# Create an instance from configuration
config = {
"implementation": "sqlite",
"sqlite": {
"database": "app.db",
"timeout": 30
}
}
# Create instance from configuration
db = Database.create_instance(config)
# Create instance by name
postgres_db = Database.create_instance(implementation="postgres", host="localhost", port=5432)
# or
postgres_db = Database.get_implementation("postgres")(host="localhost", port=5432)
# Get available implementations
implementations = Database.get_implementations()
print(implementations) # ['sqlite', 'postgres', 'mysql']
Development
Running Tests
python -m unittest discover -s tests
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License
Metadata
Release files for pythils 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pythils-0.1.1.tar.gz | 15.4 kB | Without provenance | Details for pythils-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pythils-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pythils-0.1.1-py3-none-any.whl |
Total release size: 26.0 kB
Release files / pythils-0.1.1.tar.gz
| Download URL | pythils-0.1.1.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1a041b3d917f5b930c3d3cc7877e59111e585b0f84ef9f2874100a6cda9766d
|
|
BLAKE2b-256 checksum How to use checksums |
a34d47f678be9c49281b18967ada92c57842f92ab63132acad4c2921892b9b09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pythils-0.1.1-py3-none-any.whl
| Download URL | pythils-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f15c78ccb22a49b6b83af3fef27aded08d95500192f2cdee7bc21e379253216
|
|
BLAKE2b-256 checksum How to use checksums |
bca55a924b06d4a28bf2c116e860391eab41306b4cf8fd0d763cc5fbf658b625
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for pythils 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.