Skip to main content

Common application configuration management.

Project description

Package Version PyPI - Status Tests Status Code Coverage Percentage Project License Python Versions

🏗️ 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

GitHub last commit Copier Hatch pre-commit Pyright Ruff PyPI - Implementation PyPI - Wheel

Other Projects by This Author 🌟

  • python-absence (absence on PyPI)

    🕳️ A Python library package which provides a sentinel for absent values - a falsey, immutable singleton that represents the absence of a value in contexts where None or False may be valid values.

  • python-accretive (accretive on PyPI)

    🌌 A Python library package which provides accretive data structures - collections which can grow but never shrink.

  • python-classcore (classcore on PyPI)

    🏭 A Python library package which provides foundational class factories and decorators for providing classes with attributes immutability and concealment and other custom behaviors.

  • python-dynadoc (dynadoc on PyPI)

    📝 A Python library package which bridges the gap between rich annotations and automatic documentation generation with configurable renderers and support for reusable fragments.

  • python-falsifier (falsifier on PyPI)

    🎭 A very simple Python library package which provides a base class for falsey objects - objects that evaluate to False in boolean contexts.

  • python-frigid (frigid on PyPI)

    🔒 A Python library package which provides immutable data structures - collections which cannot be modified after creation.

  • python-icecream-truck (icecream-truck on PyPI)

    🍦 Flavorful Debugging - A Python library which enhances the powerful and well-known icecream package with flavored traces, configuration hierarchies, customized outputs, ready-made recipes, and more.

  • python-mimeogram (mimeogram on PyPI)

    📨 A command-line tool for exchanging collections of files with Large Language Models - bundle multiple files into a single clipboard-ready document while preserving directory structure and metadata… good for code reviews, project sharing, and LLM interactions.

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

emcd_appcore-1.3.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

emcd_appcore-1.3-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file emcd_appcore-1.3.tar.gz.

File metadata

  • Download URL: emcd_appcore-1.3.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for emcd_appcore-1.3.tar.gz
Algorithm Hash digest
SHA256 03715d6f32c26c929d47de5fcaf074b22c4940fe4e0aeb27a0affc9a887bfced
MD5 da3056202d51750a14c19bf7381cd728
BLAKE2b-256 304ac0db8e441d354ea9348838482501abbd5134618693cccbdf0a5049f1e852

See more details on using hashes here.

Provenance

The following attestation bundles were made for emcd_appcore-1.3.tar.gz:

Publisher: releaser.yaml on emcd/python-appcore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file emcd_appcore-1.3-py3-none-any.whl.

File metadata

  • Download URL: emcd_appcore-1.3-py3-none-any.whl
  • Upload date:
  • Size: 31.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for emcd_appcore-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6c5637529dcf878ec029da06d57e92a888759b6a53b9099cc38424519323ba96
MD5 4078a690eb37d03b051d84956ea5a6b0
BLAKE2b-256 00218c924101effe79bea41335560ac08704e9d8cd30749bca9b60ea49fdfa99

See more details on using hashes here.

Provenance

The following attestation bundles were made for emcd_appcore-1.3-py3-none-any.whl:

Publisher: releaser.yaml on emcd/python-appcore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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