Skip to main content

simple setting decorator framework and platform-independent path library

Project description

pureconfig

Document Specification

  • System Version: 0.1.0
  • Document Version: v1.0.0
  • Last Modified: 2026-07-09

Installation

pip install pureconfig

Quick Start

path library

this is a function return the path of app home.

from pureconfig import get_app_home

# case 1:
# get a platform home path
app = get_app_home()
print(app)
# returns a native home path

# case 2:
# get a 
get_app_home('My Module')
# returns .../My Module

this function returns native pathlib.Path instance

Supported Platforms and Mapping

  • on Windows: %LocalAppData%
  • on Linux: ~/.config or custom $XDG_CONFIG_HOME
  • on Mac: ~/Library/Application Support
  • on AOS, IOS: app container path

for Windows, Linux, Mac:

when moduleName attribute is not None,
given modultName is extended to default mapping.

  • on Windows: C:/Users/<user>/AppData/Local/My Module
  • on Linux: ~/.config/My Module
  • on Mac: ~/Library/Application Support/My Module

configuration decorator

this is a decorator function that construct class automatically.

from pureconfig import configurate

def your_function_here(key: str) -> Any:
    if key == 'yourSetting':
        return 'setting-value'
    elif key == 'yourPath':
        return 'some/path/here'
    elif key == 'yourOption':
        return True
    elif key == 'yourID':
        return 100

@configurate(your_function_here)
class MySetting:
    yourSetting: str
    yourPath: Path
    yourOption: bool
    yourID: int

this equivalant with:

class MySetting:
    yourSetting = str('setting-value')
    yourPath = Path('some/path/here')
    yourOption = bool(True)
    yourID = int(100)

why this useful?

this decorator is built to handle variant option(s) under setting. so, you can do like this:

from pureconfig import configurate

# to handle Path, pathlib should import.
from pathlib import Path

# setting some value provider
setting_values = {
    "name": "james",
    "email": "example@example.exp",
    "department": "Customer Service",
    "db_access": False,
    "on_work": True,
    "ID": 95,
    "pc_home": "C:/Users/james"
}

# since value provider is dictionary, so i wrapped with lambda function.
# provider function should be take 1 str, return 1 data for given key.
# the "key" argument transfer the string value same as attribute that defined under your class definition.
@configurate(lambda key: setting_values[key])
class Information:
    # this class now only has name, email, department field.
    name: str
    email: str
    department: str

@configurate(lambda key: setting_values[key])
class PCSetting:
    # this class now only has name, db_access, ID, pc_home field.
    name: str
    db_access: bool
    ID: int
    pc_home: Path
@configurate(lambda key: setting_values[key])
class AllConfig:
    # this class now have all keys from setting_values
    name: str
    email: str
    department: str
    db_access: bool
    on_work: bool
    ID: int
    pc_home: Path

you can make any combination of field name for configuration, with single value provider function.
or, you can pass any custom-provider-function to use different value.

Future Update

  • frozen option
  • instantize option

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

pureconfig-0.1.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

pureconfig-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file pureconfig-0.1.0.tar.gz.

File metadata

  • Download URL: pureconfig-0.1.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pureconfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 58758711c81a4974017a8f3f951d7a94b1783874418aa91539e6de2a67721ad0
MD5 cfb73792b14c84fa1e3750fe1ee2b37e
BLAKE2b-256 54e5b5ddf281b6642fb7c99b899e1196b4879b37a2a5119a19b164cd6e63ccda

See more details on using hashes here.

File details

Details for the file pureconfig-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pureconfig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pureconfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c23111d71ecffd4bcaf990817ab7d3785f9723cd8872184b65061b46e0d80362
MD5 1b1de30ef5a2feb0da66352e2c809720
BLAKE2b-256 3b92d42ced2741f3500d61463f8b771befc6f7466ae8b57e72ecb31289f2c01b

See more details on using hashes here.

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