Skip to main content

cfgtools

Provides tools for managing config files.

Installation

$ pip install cfgtools

Requirements

pyyaml
lazyr
Faker
htmlmaster
toml
click

Usage

Save to a config file

>>> import cfgtools as cfg
>>> f = cfg.config({"foo": "bar", "this": ["is", "an", "example"]})
>>> f.save("test.cfg", "yaml") # or: f.to_yaml("test.cfg")

If not specifeid, the format of the file will be automatically detected according to the file suffix. Valid formats include ini, json, yaml, pickle, toml, etc. For example:

>>> f.save("test.yaml") # a yaml file is created
>>> f.save("test.pkl") # a pickle file is created
>>> f.save("unspecified.cfg") # by default a json file is created

Read from a config file

>>> cfg.read("test.cfg")
cfgtools.config({'foo': 'bar', 'this': ['is', 'an', 'example']})

The encoding and format of the file will be automatically detected if not specified.

Modify configs

>>> f["foo"] = None
>>> f["that"] = {"is": ["also", "an", "example"]}
>>> f
cfgtools.config({
    'foo': None, 'this': ['is', 'an', 'example'],
    'that': {'is': ['also', 'an', 'example']},
})

If user wants to check the changed items, run:

>>> f.view_change()         # auto mode now uses light style
>>> f.view_change("light")  # optimized for light/white backgrounds
>>> f.view_change("dark")   # optimized for dark/black backgrounds

See Also

Github repository

PyPI project

License

This project falls under the BSD 3-Clause License.

History

v0.1.0

  • Improved HTML rendering for large trees by collapsing/paginating overflow nodes for better readability.
  • Enhanced view_change() display styles with explicit light / dark themes and refined auto-mode behavior for consistent output.

v0.0.9

  • Bugfix when reading text files.

v0.0.8

  • Added a simple cli command cfg [OPTIONS] FILENAME.
  • Renamed ConfigIOWrapper.safematch() to ConfigIOWrapper.adapt().

v0.0.7

  • New method for BasicWrapper: *.asstr(), *.asint(), *.asfloat(), *.asbool(), *.asnone().

v0.0.6

  • Beautified the output of ConfigIOWrapper.view_change() through _repr_mimebundle_().

v0.0.5

  • Added support for .toml files.
  • New method for ConfigIOWrapper: *.view_change(), *.asdict(), *.aslist().

v0.0.4

  • Fixed a bug in path resolution.

v0.0.3

  • Added reliance on htmlmaster.

v0.0.2

  • New method ConfigIOWrapper.safematch().

v0.0.1

  • Initial release.

Metadata

Release files for cfgtools 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cfgtools 0.1.0
File Size Uploaded
cfgtools-0.1.0.tar.gz 18.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cfgtools 0.1.0
File Interpreter ABI Platform
cfgtools-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.3 kB

Release files / cfgtools-0.1.0.tar.gz

Download URL cfgtools-0.1.0.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a4c9b63b08088836d7d38d739014ae3f22fda9c72854cf8cef10fd7b61c88421
BLAKE2b-256 checksum
How to use checksums
9916765ea5b5dc9fb0bcb75dabc4462d343d7313f91b52b9a159861fb8ab5c15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / cfgtools-0.1.0-py3-none-any.whl

Download URL cfgtools-0.1.0-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84b078dd5b7f144d9bb1fb45143600141fcebd25643b7520dff45141f0f28536
BLAKE2b-256 checksum
How to use checksums
014b56197f593b8958f538543e0037221b930c7d961b6fade13c3f5e4584851b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page