Skip to main content

Reads user configuration files that written in an extremely simple way

Project description

SuperSimpleConfig

https://github.com/shengj1ang/SuperSimpleConfig

SuperSimpleConfig is a lightweight Python library designed to read user configuration files written in an extremely simple manner. Its goal is to offer an easy and intuitive way to handle configuration files, making the reading and application of configurations straightforward and hassle-free.

中文文档

Features

  • No block structure; each configuration item is on its own line.
  • All spaces are ignored.
  • Automatic detection of data types (integer, float, string, boolean).
  • By default, quotes are not needed for strings. If you want to force a numerical value to be treated as a string, you can manually add quotes like "123456".
  • Super simple syntax.
  • Read-only functionality; does not support writing.

Installation

You can install SuperSimpleConfig via pip:

pip install SuperSimpleConfig

Quick Start

Here's a simple example of how to use SuperSimpleConfig:

First, create a configuration file. There are no specific requirements for the file name and extension. Here, we use config.txt as an example, with the following content:

// You can write comments at the beginning
domain=example.com // Comments can go here as well
// Comments are also allowed here
max_requests=5 // Automatically identified as int
pi=3.1415 // Automatically identified as float

// Empty lines are also okay

Here's another example of a configuration file:

// Configuration File
// pip install pyserial
// pip install telepot
 // Configuration File
 // https://api.telegram.org/botxxxx

phonenum="008613588888888" // Phone number, optional but useful for distinction in multiple instances.
max_error_count=10 // Maximum error count limit
timezone=0 // Time zone, integer type
serialPort=COM3 // Serial port, in Windows you can use ../test/serial_init.cmd to get it
baudRate=115200 // Baud rate
schedule_reconnect_max=20.0 // Force reconnect to serial port if not refreshed in X seconds

db_path=database/example.db // Database path
sms_send_allow=True // Allow sending SMS?
sms_auto_send=False // Enable auto-reply for 11-digit incoming calls

sms_limit=1 // Maximum number of auto-reply SMS
sms_auto_send_content=Hello, the phone number you dialed has been changed to xxxxx, please contact for any matters. // Content of auto-reply
current_phonenum_log=True // Display the local phone number in local messages?

enable_telegram=True // Enable Telegram
bot=1234567890:AAAA00xxxxxxxxxx // Bot parameters
tg_api_base_link=https:\/\/api.telegram.org
tg_chat_id="-00000000" // Telegram group ID
current_phonenum_tg=True // Display the local phone number in Telegram messages?

flask_host=0.0.0.0
flask_port=8908
flask_production_mode=False

Then, you can use the following code to read and use these configurations:

from SuperSimpleConfig import UserConfig

configs = UserConfig().read("config.txt")

#UserConfig().read("FilePath")  #return a dictionary
#UserConfig().show("FilePath") #print the config

print(configs)
Value1=configs['flask_host']
Value2=congis["flask_port"]

Configuration File Format

our configuration file should follow these simple rules:

  • Each configuration item is defined on a single line as key=value. Empty lines are allowed.
  • Comments can be added at the end of a line, starting with //.
  • Quotes are not necessary for strings unless you want to force an integer or float to be treated as a string.
  • Escape character: Use // to include // in your text. e.g. https://www.python.org

License

SuperSimpleConfig is released under the MIT License. For more details, please see the LICENSE file.

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

SuperSimpleConfig-2023.12.13.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

SuperSimpleConfig-2023.12.13-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file SuperSimpleConfig-2023.12.13.tar.gz.

File metadata

  • Download URL: SuperSimpleConfig-2023.12.13.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for SuperSimpleConfig-2023.12.13.tar.gz
Algorithm Hash digest
SHA256 6fa5fcce7e8a1961400d8df16d27e653f47e4d32e5f52d29344aa1c89898af80
MD5 2feb3a6cc02a978b1e78e55ea554733b
BLAKE2b-256 dd51dda104bb53918410293fa4d72efb601065fd3dabb47ca506ae869a352cee

See more details on using hashes here.

File details

Details for the file SuperSimpleConfig-2023.12.13-py3-none-any.whl.

File metadata

File hashes

Hashes for SuperSimpleConfig-2023.12.13-py3-none-any.whl
Algorithm Hash digest
SHA256 a99f181a35fa3149d9b7bb82888a367f7de0696521bb7910c43afedff2296be5
MD5 9a36259ab255024c257562cd9a29ec19
BLAKE2b-256 ead98cd5c2c5e549c49b420188c2ef0b22ea7a9b7c1143b8ba223ee11cedc01d

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