Skip to main content

Provides tools for managing config files.

Project description

cfgtools

Provides tools for managing config files.

Installation

$ pip install cfgtools

Requirements

pyyaml
lazyr
Faker
htmlmaster
toml

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()

See Also

Github repository

PyPI project

License

This project falls under the BSD 3-Clause License.

History

v0.0.9

  • Bugfix when reading text files.

v0.0.8

  • Add a simple cli command cfg [OPTIONS] FILENAME.
  • Rename 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.

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

cfgtools-0.0.9.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

cfgtools-0.0.9-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file cfgtools-0.0.9.tar.gz.

File metadata

  • Download URL: cfgtools-0.0.9.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for cfgtools-0.0.9.tar.gz
Algorithm Hash digest
SHA256 91e8ab2e63c86beb0511046e9bb247b464e6d8256cafb8257430e3a41aa2bf01
MD5 f7ca3ad91aded0c670ffd0cb985cb84f
BLAKE2b-256 c92119a43399bf155dadfe6c21dbe5c15328b5375f0fab2b80b1591eeaf74ca2

See more details on using hashes here.

File details

Details for the file cfgtools-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: cfgtools-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for cfgtools-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 93bd17866b30391918bcf5987cdcdec743a45e6d901335be8704591dc1ade270
MD5 0cf0a42c187386da24ee1c73ec24c221
BLAKE2b-256 86765f85bfc5fc45f0700d59d084337ec9171c8f8a16ad1bb5fa5bc3fa13f226

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