Skip to main content

UserConf is a user configuration management Python library.

Project description

UserConf

本项目在UserConf基础上,做了一些调整,具体如下:

  • 配置文件存储位置, 由用户目录调整到当前目录;
  • 中文支持: json文件统一使用utf-8编码; Key支持中文;
  • 增加对Python 3.8 的支持;
  • 去除对 os.path 的依赖;
  • FilesManager 支持创建多层级目录
  • 最后重新打包(fhuserconf);

Install from PyPI (Python Package Index)

pip install fhuserconf

UserConf is a user configuration management Python library. It stores key-value settings in a JSON file and manages data files and directories. The JSON file and the data files and directories are inside a directory that is inside the user home directory.

Usage example

from userconf import UserConf

# Create an instance of the UserConf class providing an application ID. The
# settings JSON file is "settings.json" and the directory for data files and
# directories is "files". The "settings.json" file and the "files" directory
# will be created inside a directory which name is a period (".") followed by
# the application ID, which will be created inside the user's home directory
# (e.g. "/home/user/.app/settings.json" and "/home/user/.app/files" in Linux).
uc = UserConf("example-app")

# Set a setting value given the setting key and the value. The value can be any
# object serializable to JSON (a string, an integer, a list, a dictionary...).
uc.settings.set("example-key", "Example value")

# Get a setting value given the setting key. If the key doesn't exist, None is
# returned.
value = uc.settings.get("example-key")
print(value)

# Set a default value to return if the setting doesn't exist
value = uc.settings.get("example-key-2", "Default value")
print(value)

# Delete a setting given its key
uc.settings.delete("example-key")

# Delete all the settings
uc.settings.delete_all()

# Get an absolute path for a data file. This doesn't create the file but it
# creates its directory and all the intermediate directories if they don't
# exist, so that the application using this library can save data in this path
# without having to create its directory.
path = uc.files.get_path("example-file.txt")
print(path)

How to install

We can install UserConf in the following ways:

Install from PyPI (Python Package Index)

pip install userconf

Install from the source code

python setup.py install

Generate a package and install it

We can generate and install the built package or the source archive from the source code. The wheel package is needed for generating the built package.

To generate and install the built package (preferred), run the following commands from the project directory:

pip install wheel
python setup.py bdist_wheel
pip install ./dist/userconf*.whl

To generate and install the source archive, run the following commands from the project directory:

python setup.py sdist
pip install ./dist/userconf*.tar.gz

How to run the unit tests

To run all the unit tests, run the following command from the project directory:

python -m unittest discover test

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

fhuserconf-0.5.11.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

fhuserconf-0.5.11-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file fhuserconf-0.5.11.tar.gz.

File metadata

  • Download URL: fhuserconf-0.5.11.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.10 Windows/10

File hashes

Hashes for fhuserconf-0.5.11.tar.gz
Algorithm Hash digest
SHA256 01d40b5c663aee785d13c89184647256fe852b9ec43f959972cb0e47fab0c9d2
MD5 25a5251bbeb242574050182e93b46135
BLAKE2b-256 1173456e06383e5f6655c32d0f362656a2229bc200f4396725d74b385906a41e

See more details on using hashes here.

File details

Details for the file fhuserconf-0.5.11-py3-none-any.whl.

File metadata

  • Download URL: fhuserconf-0.5.11-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.10 Windows/10

File hashes

Hashes for fhuserconf-0.5.11-py3-none-any.whl
Algorithm Hash digest
SHA256 ae0085f5aa17abbea0c6351fd269a4995616b9d3fb22c48dc419e4bc7a9c8134
MD5 749e6e71dbb8c6d4f62f7bb6778860bb
BLAKE2b-256 f67b94f563976c5d725199a58ead3498cc3f59d87864ac2f58c8ea226ceb1910

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