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.1.tar.gz (17.4 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.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for confng_py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ee5611eac495cf155303821b17ba0df7f757a9eb79ace2b104709bc8528c895f
MD5 7717575d5727b7113d01a22c8fa21ab7
BLAKE2b-256 f246ad8b1f6ccd5a2dc4af09324f0e28f35ed3aec13e9608b015999d42221f65

See more details on using hashes here.

Provenance

The following attestation bundles were made for confng_py-0.2.1.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.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for confng_py-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6657a5cc294f3357b27f85c264995ae7517fb7bf10fe66687497e0e935cf6d23
MD5 6fd5c29f45c86d2af9a800150490ce1c
BLAKE2b-256 54f4482205b965d6e691a32db7495e04cd9c3fdb3a886a9ca5f35dabeecb041e

See more details on using hashes here.

Provenance

The following attestation bundles were made for confng_py-0.2.1-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