Skip to content

inokufu/python-config

ConfigCore

Python License GitHub Actions Pytest EditorConfig uv Ruff ty Pre-commit Makefile MkDocs

Overview

ConfigCore provides a minimal, type-safe foundation for building configuration systems in Python applications. Rather than being a complete configuration solution, it defines contracts and base classes that can be extended to create application-specific configuration systems.

The library focuses on:

  • πŸ”„ Providing a standardized way to handle environment selection
  • πŸ“Š Managing log levels consistently across projects
  • 🧩 Offering a base Settings class for extension
  • πŸ“ Using Pydantic for type validation and .env file loading

Setup and installation

Prerequisites

  • Python 3.13 or higher
  • uv for dependency management

Installation

  1. Clone the repository

  2. Install dependencies

    make init

Usage

Extending the Base Settings

ConfigCore is designed to be extended in your projects. Here's how to use it:

from configcore import Settings
from pydantic import Field


class MyAppSettings(Settings):
  """Application-specific settings extending the base Settings class."""

  # Add your application-specific settings
  api_url: str = Field(default="https://api.example.com")
  max_retry_count: int = Field(default=3, ge=1)
  timeout_seconds: float = Field(default=30.0)

  # Add custom methods as needed
  def get_api_timeout(self) -> float:
    if self.is_env_production():
      return self.timeout_seconds
    return self.timeout_seconds * 2

Using Your Configuration

# In your application
settings = MyAppSettings()  # Loads from environment variables / .env

# Access standard settings from the base class
env = settings.get_environment()  # Returns Environment enum
log_level = settings.get_log_level()  # Returns LogLevel enum
is_prod = settings.is_env_production()  # Convenience method

# Access your custom settings
api_url = settings.api_url
timeout = settings.get_api_timeout()

Development

Code Formatting and Linting

This project uses ruff for formatting and linting:

# Format code
make format

# Run linters
make lint

Running Tests

# Run tests with coverage
make test

Environment Variables

Variable Description Default Value Possible Values
ENVIRONMENT Application environment PRODUCTION DEVELOPMENT, STAGING, PRODUCTION
LOG_LEVEL Logging level INFO DEBUG, INFO, WARNING, ERROR, CRITICAL

Contributing

We welcome contributions to this project! Please see the CONTRIBUTING.md file for guidelines on how to contribute, including:

  • How to set up your development environment
  • Coding standards and style guidelines
  • Pull request process
  • Testing requirements

License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0) - see the LICENSE file for details.

GPL-3.0 is a strong copyleft license that requires anyone who distributes your code or a derivative work to make the source available under the same terms.

About

Provides a minimal, type-safe foundation for building configuration systems in Python applications

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors