Common application configuration management.
Project description
🏗️ A Python library package which provides application foundation components - streamlined async initialization, configuration management, platform directories, logging setup, and environment handling for Python applications.
Key Features ⭐
🚀 Async Application Initialization: Single prepare() function that sets up your entire application foundation with sensible defaults.
📁 Platform Directory Management: Automatic discovery and creation of platform-specific directories for configuration, data, and cache.
⚙️ TOML Configuration System: Hierarchical configuration loading with includes, template variables, and overrides. Can bring your own configuration system too.
🎯 Distribution Detection: Automatic detection of development vs production deployment modes with package introspection.
📝 Logging Configuration: Logging setup with plain and rich modes and environment variable overrides.
🔄 Resource Management: Integration with AsyncExitStack for proper cleanup of async resources.
🏷️ Safety: Full type annotations with immutable data structures for thread safety.
Installation 📦
Method: Install Python Package
Install via uv pip command:
uv pip install emcd-appcore
Or, install via pip:
pip install emcd-appcore
Examples 💡
Quick Start 🚀
The simplest way to initialize your application:
>>> import asyncio
>>> import contextlib
>>> import appcore
>>> async def main( ):
... async with contextlib.AsyncExitStack( ) as exits:
... # Initialize application core with auto-detection
... auxdata = await appcore.prepare( exits )
... print( f"App: {auxdata.application.name}" )
... print( f"Mode: {'dev' if auxdata.distribution.editable else 'prod'}" )
... return auxdata.configuration
>>> # asyncio.run( main( ) ) # Returns configuration dictionary
Configuration Access ⚙️
Access your application’s TOML configuration:
>>> async def show_config( ):
... async with contextlib.AsyncExitStack( ) as exits:
... auxdata = await appcore.prepare( exits )
... config = auxdata.configuration
... # Configuration loaded from general.toml in user config directory
... print( f"Available sections: {list( config.keys( ) )}" )
... # Access nested configuration values
... if 'app' in config:
... print( f"App name: {config[ 'app' ].get( 'name', 'Unknown' )}" )
... return config
>>> # asyncio.run( show_config( ) )
Platform Directories 📁
Access platform-specific directories for your application:
>>> async def show_directories( ):
... async with contextlib.AsyncExitStack( ) as exits:
... app_info = appcore.ApplicationInformation(
... name = 'my-app', publisher = 'MyCompany' )
... auxdata = await appcore.prepare( exits, application = app_info )
... dirs = auxdata.directories
... print( f"Config: {dirs.user_config_path}" )
... print( f"Data: {dirs.user_data_path}" )
... print( f"Cache: {dirs.user_cache_path}" )
>>> # asyncio.run( show_directories( ) )
Logging Configuration 📝
Configure logging with Rich support and environment overrides:
>>> import appcore >>> async def setup_logging( ): ... async with contextlib.AsyncExitStack( ) as exits: ... # Rich logging with environment variable support ... inscription = appcore.inscription.Control( ... mode = appcore.inscription.Modes.Rich, level = 'debug' ) ... auxdata = await appcore.prepare( exits, inscription = inscription ) ... # Logging level can be overridden via MY_APP_INSCRIPTION_LEVEL ... return "Logging configured" >>> # asyncio.run( setup_logging( ) )
Dependencies & Architecture 🏛️
Appcore is built on a foundation of proven, lightweight dependencies:
Configuration: Uses standard library tomli for TOML parsing with accretive data structures that can grow but never shrink.
Platform Integration: Leverages platformdirs for cross-platform directory discovery and aiofiles for async file operations.
Logging Enhancement: Optional integration with Rich for enhanced console output with graceful fallbacks.
Distribution Management: Uses importlib-metadata and importlib-resources for package introspection and resource handling.
The architecture emphasizes:
Immutability: All configuration and state objects are immutable after creation, preventing accidental modifications.
Async-First: Built from the ground up for async/await patterns with proper resource management.
Dependency Injection: Configurable components that can be replaced or extended without modifying core functionality.
Type Safety: Comprehensive type annotations for excellent IDE support and static analysis.
Contribution 🤝
Contribution to this project is welcome! However, it must follow the code of conduct for the project.
Please file bug reports and feature requests in the issue tracker or submit pull requests to improve the source code or documentation.
For development guidance and standards, please see the development guide.
More Flair
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
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 emcd_appcore-1.0.1.tar.gz.
File metadata
- Download URL: emcd_appcore-1.0.1.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f7d7f7e112738b7bd411c6697369328528f61868b7dbe9f982614eec75b89a8
|
|
| MD5 |
9d7048ac74e21d8792768428ea6889a2
|
|
| BLAKE2b-256 |
ed999d2866df2ffbc8ad873d1a8462f5ccee9e7d2aad1f2518dad3b9eba0ec1e
|
Provenance
The following attestation bundles were made for emcd_appcore-1.0.1.tar.gz:
Publisher:
releaser.yaml on emcd/python-appcore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
emcd_appcore-1.0.1.tar.gz -
Subject digest:
2f7d7f7e112738b7bd411c6697369328528f61868b7dbe9f982614eec75b89a8 - Sigstore transparency entry: 271072009
- Sigstore integration time:
-
Permalink:
emcd/python-appcore@788bf18fbe3f8232724aea2e2f26421a8943645d -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/emcd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
releaser.yaml@788bf18fbe3f8232724aea2e2f26421a8943645d -
Trigger Event:
push
-
Statement type:
File details
Details for the file emcd_appcore-1.0.1-py3-none-any.whl.
File metadata
- Download URL: emcd_appcore-1.0.1-py3-none-any.whl
- Upload date:
- Size: 30.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
120a2132d81c6c0db87b0d6cc7005c5e02d73c39163698df33e60cb6dd761e93
|
|
| MD5 |
9b56663c8ebce54913c0295b795f344d
|
|
| BLAKE2b-256 |
f586a6d128247c4ef3448cf89c6ef66b7a3883ae4ed109e1591cc1068d492e02
|
Provenance
The following attestation bundles were made for emcd_appcore-1.0.1-py3-none-any.whl:
Publisher:
releaser.yaml on emcd/python-appcore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
emcd_appcore-1.0.1-py3-none-any.whl -
Subject digest:
120a2132d81c6c0db87b0d6cc7005c5e02d73c39163698df33e60cb6dd761e93 - Sigstore transparency entry: 271072011
- Sigstore integration time:
-
Permalink:
emcd/python-appcore@788bf18fbe3f8232724aea2e2f26421a8943645d -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/emcd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
releaser.yaml@788bf18fbe3f8232724aea2e2f26421a8943645d -
Trigger Event:
push
-
Statement type: