A small collections of modular components useful in other projects.
Project description
projectutils
A small collections of modular components useful in other projects.
projectutils.init
The init
module is helpful when you need to create a complex directory structure.
You can create objects that represent Directories and Files to create a tree.
from pathlib import Path
from projectutils.init import Tree, Directory, File
tree = Tree([
Directory("dir1"),
Directory("dir2", [
File("file.txt", "file content")
])
])
tree.create(Path("~/project").expanduser())
# $ tree ~/project
# ~/project
# ├── dir1
# └── dir2
# └── file.txt
projectutils.config
The config
module allows you to define a configuration schema and dinamically load configurations
from multiple sources.
schema.json
:
{
"string": {"doc": "String config", "format": "string", "default": "DEFAULT"},
"integer": {"doc": "Integer config", "format": "int", "default": 1},
"float": {"doc": "Float config", "format": "float", "default": 1.1},
"list": {"doc": "List config", "format": "list", "default": ["a", "b", "c"]},
"bool": {"doc": "Bool config", "format": "bool", "default": true},
"nested.string": {"doc": "String config", "format": "string", "default": "DEFAULT"},
}
/etc/myapp/config.json
:
{
"float": 2.2,
"string": "loaded from json",
"nested": {
"string": "loaded from json"
}
}
/etc/myapp/.env
:
MYAPP_CONF_LIST="e,n,v"
MYAPP_CONF_BOOL="False"
MYAPP_CONF_NESTED_STRING="loaded from env"
app.py
:
import json
from pathlib import Path
from projectutils.config import Config, ENVSource, JSONSource, ConfigSchema
# Load schema
schema = ConfigSchema.from_json_file("schema.json")
# Define Sources
envs_prefix = "MYAPP_CONF_"
configs_root = Path("/etc/myapp")
sources = [
JSONSource(configs_root / "config.json"),
ENVSource(envs_prefix, configs_root),
]
# Source definition dictates precedence.
# In this case ENV values will override JSON values.
# Load config
config = Config(schema, sources)
config.get("integer")
# 1
config.get("float")
# 2.2
config.get("bool")
# False
config.get("list")
# ['e', 'n', 'v']
config.get("nested.string")
# 'loaded from env'
config.get("string")
# 'loaded from json'
config.get("nested")
# {'nested': 'loaded from env'}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
projectutils-1.2.tar.gz
(20.0 kB
view details)
Built Distribution
File details
Details for the file projectutils-1.2.tar.gz
.
File metadata
- Download URL: projectutils-1.2.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34e63efa2a044109e46d5f45f70d624f08b97249c141a45f58c7de972e045860 |
|
MD5 | 305cb0ab7e388d220e9433e979a15fe2 |
|
BLAKE2b-256 | 27f62b0f4947df40a9b90192b133c96082d048ee0c9f03c5b2121fc473959616 |
File details
Details for the file projectutils-1.2-py3-none-any.whl
.
File metadata
- Download URL: projectutils-1.2-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af39189462c71cae6b0a642fbbfe35845b2b50b46982707ab43135887272a029 |
|
MD5 | ecf8a2e03ca258fa6cab6829acc79de9 |
|
BLAKE2b-256 | 75be716684c1dbbf4a932a97633da093c6cbd87511e570c1f9310dcbf431b2bc |