Skip to main content

A simple configuration management tool for python.

Project description

confng-py

A simple configuration management tool for python. You can use it to manage your python application's configuration in a simple and flexible way.

Install

pip install confng-py

Usage

from confng import Conf

# create a new Conf instance with a config object and MergeEnvOptions
# If you don't want to merge environment variables, you can omit the merge_env_options option.
# The value of `config` is JSON. You can parse it from json/toml/yaml/... file, or directly pass an object.
# The logic should be implemented in your own code.
conf = Conf(
    ConfOptions(
        config={
            "name": "foo",
            "server": {
                "port": 3000,
                "host": "localhost",
            },
            "logs": [
                {
                    "level": "info",
                    "output": "console",
                },
            ],
            "nums": [1, 2, 3],
        },
        merge_env_options=MergeEnvOptions(prefix="FOO", separator="__"),
    )
)

print(conf.get('name')); # foo
print(conf.get('server.port')); # 3000
print(conf.get('server.host')); # localhost

# The inner of Conf will guess the type of the value automatically from the initial config object.
# So the inital config object should be in full form, and the value of each key should be in the correct type.

# if the following environment variables setted 
# FOO__SERVER__PORT=4000 
# FOO__SERVER__HOST=example.com
print(conf.get('server.port')); # here will return 4000 and the data type is number.
print(conf.get('server.host')); # example.com

Load config from file

import os
import json

from confng import Conf

# read config from conifg/default.json
config_path = os.path.join('config', 'default.json')
with open(config_path, 'r') as f:
    config = json.load(f)

conf = Conf(ConfOptions(config=config))

print(conf.get('name'));

Thanks

This package is inspired by the following packages:

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

confng_py-0.2.2.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

confng_py-0.2.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file confng_py-0.2.2.tar.gz.

File metadata

  • Download URL: confng_py-0.2.2.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for confng_py-0.2.2.tar.gz
Algorithm Hash digest
SHA256 de6b956a9ff1d75b6e755e57ca6c6a59b2c1cd55686d3ae3c582ba70cc6cca0c
MD5 e5fced53d69e07016c4ef123a2532566
BLAKE2b-256 381bfdbe27224fad0300c096e228c237ad195168a4a6cca74733c05ea8b25fc7

See more details on using hashes here.

Provenance

The following attestation bundles were made for confng_py-0.2.2.tar.gz:

Publisher: publish.yml on SethWen/confng-py

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

File details

Details for the file confng_py-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: confng_py-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for confng_py-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 08073a3a19d7e5960cda8ec225c8c05c0803e01827f4606df2df3fb56f8b43d0
MD5 e6a70f5e215d76378772542091d192c3
BLAKE2b-256 4794ebf64ac465a3265f82d88026005b869f22135f6eacd1778be6cff0c9e7b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for confng_py-0.2.2-py3-none-any.whl:

Publisher: publish.yml on SethWen/confng-py

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