Skip to main content

simple setting decorator framework and platform-independent path library

Project description

pureconfig

Document Specification

  • System Version: 0.1.1
  • 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.1.tar.gz (3.7 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.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pureconfig-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 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.1.tar.gz
Algorithm Hash digest
SHA256 f41515afc3f5ff46d8a114e4e67a7eaaf8dacffc7fdfe024ce76c597af98ba05
MD5 f5943df35c3e818977ae2b8bb45ecfdd
BLAKE2b-256 0bb38bb22c2820d7f63c1d124075e543332d454f08633faec945bb71f58f4586

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pureconfig-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bcb30b88731fddf8c6efbd6d96b30df05a1814ab0b3efe9d5f4ce8e4d6176780
MD5 56e91a619798442c471d8bb23e459da3
BLAKE2b-256 4a49cc42bd08c36775a2abac9b589fe01eecddd10905be1db5aac8b4df47041a

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