Loader of configuration files written in Python.
Project description
gileum
Installing
- Python: >= 3.7
python -m pip install gileum
Basic Usage
gileum is a loader of configuration scripts written in Python. On gileum, a configuration can be implemented as a subclass of gileum.BaseGileum. gileum.BaseGileum
is a light-weight wrapper of pydantic.BaseModel, so you can easily implemented the subclass in almost same way as pydantic.
Developer-side
In source code of something like web application, a developer can implement a gileum class as below, which will be the interface to launch the app:
from typing import Literal
from gileum import BaseGileum
class SampleGileum(BaseGileum):
app_name: str
hostname: str
port: int
glm_name: Literal["main", "test"]
Note that all subclasses of gileum.BaseGileum
must have the field glm_name
whose type must be Literal of some strings. The field may be used as a flag and the developer may judge the flag to determine how the app should work.
After the implementaion is done, the developer can invoke gileum.load_glms_at()
specifying path of a configuration file for users to create:
from gileum import load_glms_at
load_glms_at(path_to_config)
Note that the default suffix of configuration files is .glm.py
, e.g. config.glm.py
. There is also another function named gileum.load_glms_in()
, which loads all the configuration files in specified directory.
Fianlly, the developer can access to the SampleGileum
objects loaded by calling gileum.get_glm()
function:
from gileum import get_glm
config_main = get_glm("main", SampleGileum)
config_test = get_glm("test", SampleGileum)
# Now you can access to the fields of the SampleGileum objects.
assert config_main.glm_name == "main"
assert config_test.glm_name == "test"
User-side
A user of the app above needs to create a configuration file and generate two SimpleGileum
objects. The location of the configuration file depends on apps the user uses. Now, let's assume that the name of the app package is sample_app, and in the app, the location is user's working directory. For example, the user can create a configuration file named config.glm.py
and generate the SimpleGileum
objects:
# config.glm.py
from sample_app import SimpleGileum
gileum_main = SimpleGileum(
app_name="sample_app",
hostname="example.com",
port=443,
glm_name="main"
)
gileum_main = SimpleGileum(
app_name="sample_app@test",
hostname="localhost",
port=8000,
glm_name="test"
)
That's it!! Now what you have to do the next is just to execute the app. The way of it depends on the app.
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
Built Distribution
File details
Details for the file gileum-0.2.2.tar.gz
.
File metadata
- Download URL: gileum-0.2.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fff21ac2c43e004e36cbafc7f2befa09b0affc44acd71be2c858dabbc655999 |
|
MD5 | fb14032eae95b4a7297afa58be06d1f7 |
|
BLAKE2b-256 | ab941a35a2f159d59cb592e631dc27c4a90bcbd2a931055430e12be7905f0933 |
File details
Details for the file gileum-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: gileum-0.2.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d6379d90bafd5081bf73ddad772985cd5147de820a97a601b969bf3f0bf1f32 |
|
MD5 | bd56999b23960986978a8eed2c076e9f |
|
BLAKE2b-256 | 82b1816214cbb5d53dc25011b44bac343e3d467d65c43a20ab5b7e60f0de4cca |