Skip to main content

No project description provided

Project description

keiconf

PyPI - Version PyPI - Python Version Hatch - Version

Repo - PRs Repo - Issues

A small, minimalist application json configuration tool for small projects.

Uses only stdlib if that matters to you.


Table of Contents

Why tho?

Fair question.

I originally started this project as an excuse to use Hatch and write a pyproject.toml no-distutils/setuptools python project and see how green the grass was.

I've typically been unhappy with the configuration options for python in a way I can't articulate very well, and I just wanted a simple json file read with some guiderails. Some quick user-side discovery to find my platform's config path and get going.

This project isn't meant to be a fully featured configuration system to slap into your next big webservice, it's just a small system to slap on your next prototype or small project.

Installation

pip install keiconf

Usage

from keiconf import KeiConf

k = KeiConf(filepath="path/to/file.json")
k.get("your_key")
k.get("path.to.your.nested_key")
k.start() # start watching config file for changes

Params

KeiConf(filepath, indent=2, fail_on_missing_key=False, create_if_not_exist=False, watch_for_changes=False)
  • filepath:str
    • The path to your target configuration file
    • ex. /path/to/file.json
  • indent:int
    • The json indentation to use for the written file
    • ex. 2
  • fail_on_missing_keys:bool
    • If True, will raise a KeyError if a key is missing, which you can catch and exit on.
    • If False, will return nothing
  • create_if_not_exist:bool
    • if True, will create the missing path directories and empty configuration file if it does not exist
    • if False will fail naturally on opening nonexistent configuration file
  • watch_for_changes:bool
    • if True will launch the config file watcher on init
    • if False will not launch the config file watcher on init
    • See Config File Watcher for more information

Config File Watcher

If your KeiConf instance is started with watch_for_changes=True then a threaded file watcher will load changes to your configuration file as it sees them (within keiconf._CHANGE_WATCH_INTERVAL).

If your KeiConf instance is started with watch_for_changes=False then the threaded file watcher is not created automatically.

You can stop and start the file watcher manually via the start() and stop() functions. It can be start()'ed even if you launched with watch_for_changes=False

k = KeiConf(...)
k.start() # starts the file watcher if it isn't already
k.stop() # stops a running file watcher if it is running

The file watcher and loader is protected by a threading.Lock()

Development

Development/Testing/Contribution requires hatch. Hatch provides the project management, environment abstraction, dependency resolution, and dev/test entrypoints.

python3 -m pip install hatch

although it is recommended to install hatch via pipx

python3 -m pip install pipx
python3 -m pipx ensurepath
python3 -m pipx install hatch

Limitations

  • Need to investigate behavior with lists

FAQ

  • Why not dot notation / attribute reference?
    • A: I looked into this as I was interested in possibly doing it, but it looked rather lengthy to implement and involved modifying the base class quite a bit or using wrappers and I just wasn't sure that was in the spirit of minimalism. The get() function uses a string dot notation get("path.to.key") as a sort of middle ground. --- I may revisit in the future.

License

keiconf is distributed under the terms of the MIT license.

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

keiconf-0.0.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

keiconf-0.0.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file keiconf-0.0.1.tar.gz.

File metadata

  • Download URL: keiconf-0.0.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for keiconf-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fac94f033aefb6035dd0e6111c25a1cf5e0a81a11b8f47f6870710dc9009377c
MD5 b6bc8d7279715956f1c12b74ebaf852d
BLAKE2b-256 96b3b96155962879faf04be9ec4cc2a489ea70c3a9984b162b12cdf8f843aa1f

See more details on using hashes here.

File details

Details for the file keiconf-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: keiconf-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for keiconf-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 059f6ce78b98dea0064c7e0065e99c9f01e1be529598bb7c9e1c863846741614
MD5 c2c1af9d9ba58ad528994bdc88f1f805
BLAKE2b-256 0b8d350846885a1892eace92557f634718f26137b57f0d8c59f697887b7546bf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page