Name | kurde JSON |
Version |
0.2.0
JSON |
| download |
home_page | |
Summary | Configuration Language |
upload_time | 2023-10-27 00:08:21 |
maintainer | |
docs_url | None |
author | Grzegorz Krasoń |
requires_python | >=3.8,<4.0 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# kurde
Simple configuration language based on Python.
## Features
- Python syntax
- Flexible Enums
- Easily created nested dictionaries
- Direct addess to environment variables
- Calling/capturing shell commands
- Path manipulation
- Module `re` immediately available
## Concepts
Kurde is pure Python with some built-ins added for your convenience (see below).
After invoking your script, any JSON-serializable variable defined in the global scope will be serialized and printed to stdout.
Alternatively you can define `ROOT` variable in the global scope. It will be considered as the root object to be serialized.
After installing Kurde, command `kurde` becomes available. Use it as:
```sh
kurde path/to/your/script.py
```
For clarity it is recommended to add kurde in the shebang of your script: `#!/usr/bin/env kurde`.
For more information see examples below.
## Built-Ins
| Variable | Value |
|----------|---------------|
| `Path` | `pathlib.Path` |
| `Dict` | `addict.Dict` |
| `Enum` | `simplenum.Enum` |
| `enum` | `simplenum` |
| `env` | `addict.Dict(**os.environ)` |
| `cmd` | `plumbum.local.cmd` |
| `re` | `re` |
For reference see:
- [addict](https://github.com/mewwts/addict)
- [simple-enum](https://github.com/andrewcooke/simple-enum)
- [plumbum](https://plumbum.readthedocs.io/)
## Examples
### Simple Example
```python
#!/usr/bin/env kurde
user = dict(
name = 'admin',
password = 'admin123',
)
remotes = [
'192.168.0.100',
'192.168.0.101',
'192.168.0.102',
]
timeout = 100
```
Renders as:
```json
{
"user": {
"name": "admin",
"password": "admin123"
},
"remotes": [
"192.168.0.100",
"192.168.0.101",
"192.168.0.102"
],
"timeout": 100
}
```
### Advanced Example
```python
#!/usr/bin/env kurde
# Enum from `simple-enum` package is available.
# By default enum items are serialized by names.
class Color(Enum):
red
green
blue
white
black
# Alternatively, enum items can be replaced by numbers assigned automatically.
class Priority(Enum, values=enum.from_zero):
low
medium
high
# In the simple cases, standard dictionary is sufficient.
# It is serialized as JSON object.
theme = dict(
foreground = Color.black,
background = Color.green,
)
# Dictionary can be also created by assigning the the attributes.
# Dict comes from `addicts` package.
user = Dict()
# Environment variables can be accessed directly.
user.name = env.USER or 'admin'
user.full_name = "Tom Brown"
# Module re immediately available.
user.last_name = re.findall('[^ ]+', user.full_name)[-1]
# lists, dicts, sets are serialized as JSON arrays.
user.aliases = ('tommy', 'tbrown', 'brown')
user.nick = None
network = Dict()
# Non-existing attributes are created on the fly.
network.local.priority = Priority.medium
# Shell commands can be easily invoked.
# Behind `cmd` we get `plumbum.local.cmd`.
network.local.name = cmd.hostname().strip()
# pathlib.Path immediately available.
network.local.cert_path = Path(__file__).parent.absolute() / 'cert.pem'
# Closures and other constructs available.
network.remotes = {f"proxy{n}": f'192.168.0.{100 + n}' for n in range(3)}
network.remotes['localhost'] = '127.0.0.1'
```
Renders as:
```json
{
"theme": {
"foreground": "black",
"background": "green"
},
"user": {
"name": "kendo",
"full_name": "Tom Brown",
"last_name": "Brown",
"aliases": [
"tommy",
"tbrown",
"brown"
],
"nick": null
},
"network": {
"local": {
"priority": 1,
"name": "precision",
"cert_path": "/home/kendo/wrk/kurde/examples/cert.pem"
},
"remotes": {
"proxy0": "192.168.0.100",
"proxy1": "192.168.0.101",
"proxy2": "192.168.0.102",
"localhost": "127.0.0.1"
}
}
}
```
### Example with ROOT defined
```python
#!/usr/bin/env kurde
min_value = 2
max_value = 6
ROOT = Dict()
ROOT.numbers = list(range(min_value, max_value+1))
```
Renders as:
```json
{
"numbers": [
2,
3,
4,
5,
6
]
}
```
## Disclaimer
Kurde doesn't do any sandboxing. Invoke the scripts only if you absolutely trust them. You are doing it on your own responsibility.
## Known Issues
There is an issue between addict and simplenum when calling `Dict` with enum items as arguments, e.g.:
```python
theme = Dict(
foreground = Color.white,
background = Color.green,
)
```
Raw data
{
"_id": null,
"home_page": "",
"name": "kurde",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Grzegorz Kraso\u0144",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/45/dc/30224bbfbd3001b0ab0fdc56fe989d1fdfdd2ec83c2f4588120705441983/kurde-0.2.0.tar.gz",
"platform": null,
"description": "# kurde\n\nSimple configuration language based on Python.\n\n## Features\n\n- Python syntax\n- Flexible Enums\n- Easily created nested dictionaries\n- Direct addess to environment variables\n- Calling/capturing shell commands\n- Path manipulation\n- Module `re` immediately available\n\n## Concepts\n\nKurde is pure Python with some built-ins added for your convenience (see below).\n\nAfter invoking your script, any JSON-serializable variable defined in the global scope will be serialized and printed to stdout.\n\nAlternatively you can define `ROOT` variable in the global scope. It will be considered as the root object to be serialized.\n\nAfter installing Kurde, command `kurde` becomes available. Use it as:\n```sh\nkurde path/to/your/script.py\n```\n\nFor clarity it is recommended to add kurde in the shebang of your script: `#!/usr/bin/env kurde`.\n\nFor more information see examples below.\n\n## Built-Ins\n\n| Variable | Value |\n|----------|---------------|\n| `Path` | `pathlib.Path` |\n| `Dict` | `addict.Dict` |\n| `Enum` | `simplenum.Enum` |\n| `enum` | `simplenum` |\n| `env` | `addict.Dict(**os.environ)` |\n| `cmd` | `plumbum.local.cmd` |\n| `re` | `re` |\n\nFor reference see:\n- [addict](https://github.com/mewwts/addict)\n- [simple-enum](https://github.com/andrewcooke/simple-enum)\n- [plumbum](https://plumbum.readthedocs.io/)\n\n## Examples\n\n### Simple Example\n\n```python\n#!/usr/bin/env kurde\n\nuser = dict(\n name = 'admin',\n password = 'admin123',\n)\nremotes = [\n '192.168.0.100',\n '192.168.0.101',\n '192.168.0.102',\n]\ntimeout = 100\n```\n\nRenders as:\n```json\n{\n \"user\": {\n \"name\": \"admin\",\n \"password\": \"admin123\"\n },\n \"remotes\": [\n \"192.168.0.100\",\n \"192.168.0.101\",\n \"192.168.0.102\"\n ],\n \"timeout\": 100\n}\n```\n\n### Advanced Example\n\n```python\n#!/usr/bin/env kurde\n\n# Enum from `simple-enum` package is available.\n# By default enum items are serialized by names.\nclass Color(Enum):\n red\n green\n blue\n white\n black\n\n# Alternatively, enum items can be replaced by numbers assigned automatically.\nclass Priority(Enum, values=enum.from_zero):\n low\n medium\n high\n\n# In the simple cases, standard dictionary is sufficient.\n# It is serialized as JSON object.\ntheme = dict(\n foreground = Color.black,\n background = Color.green,\n)\n\n# Dictionary can be also created by assigning the the attributes.\n# Dict comes from `addicts` package.\nuser = Dict()\n\n# Environment variables can be accessed directly.\nuser.name = env.USER or 'admin'\nuser.full_name = \"Tom Brown\"\n\n# Module re immediately available.\nuser.last_name = re.findall('[^ ]+', user.full_name)[-1]\n\n# lists, dicts, sets are serialized as JSON arrays.\nuser.aliases = ('tommy', 'tbrown', 'brown')\nuser.nick = None\n\nnetwork = Dict()\n\n# Non-existing attributes are created on the fly.\nnetwork.local.priority = Priority.medium\n\n# Shell commands can be easily invoked.\n# Behind `cmd` we get `plumbum.local.cmd`.\nnetwork.local.name = cmd.hostname().strip()\n\n# pathlib.Path immediately available.\nnetwork.local.cert_path = Path(__file__).parent.absolute() / 'cert.pem'\n\n# Closures and other constructs available.\nnetwork.remotes = {f\"proxy{n}\": f'192.168.0.{100 + n}' for n in range(3)}\nnetwork.remotes['localhost'] = '127.0.0.1'\n```\n\nRenders as:\n```json\n{\n \"theme\": {\n \"foreground\": \"black\",\n \"background\": \"green\"\n },\n \"user\": {\n \"name\": \"kendo\",\n \"full_name\": \"Tom Brown\",\n \"last_name\": \"Brown\",\n \"aliases\": [\n \"tommy\",\n \"tbrown\",\n \"brown\"\n ],\n \"nick\": null\n },\n \"network\": {\n \"local\": {\n \"priority\": 1,\n \"name\": \"precision\",\n \"cert_path\": \"/home/kendo/wrk/kurde/examples/cert.pem\"\n },\n \"remotes\": {\n \"proxy0\": \"192.168.0.100\",\n \"proxy1\": \"192.168.0.101\",\n \"proxy2\": \"192.168.0.102\",\n \"localhost\": \"127.0.0.1\"\n }\n }\n}\n```\n\n### Example with ROOT defined\n\n```python\n#!/usr/bin/env kurde\n\nmin_value = 2\nmax_value = 6\n\nROOT = Dict()\nROOT.numbers = list(range(min_value, max_value+1))\n```\n\nRenders as:\n```json\n{\n \"numbers\": [\n 2,\n 3,\n 4,\n 5,\n 6\n ]\n}\n```\n\n## Disclaimer\n\nKurde doesn't do any sandboxing. Invoke the scripts only if you absolutely trust them. You are doing it on your own responsibility.\n\n## Known Issues\n\nThere is an issue between addict and simplenum when calling `Dict` with enum items as arguments, e.g.:\n\n```python\ntheme = Dict(\n foreground = Color.white,\n background = Color.green,\n)\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Configuration Language",
"version": "0.2.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "29060f332b7b988f0faf665bdcfe5b7b975da3cdb4be2d9aa5d13431fe88153b",
"md5": "485adc73c7738b9445a16c4b0a51119b",
"sha256": "8e0e53f4f5bea81d857e1e0522b40714fd4cfab841daf66a1dc13002e82facb2"
},
"downloads": -1,
"filename": "kurde-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "485adc73c7738b9445a16c4b0a51119b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 4451,
"upload_time": "2023-10-27T00:08:19",
"upload_time_iso_8601": "2023-10-27T00:08:19.488713Z",
"url": "https://files.pythonhosted.org/packages/29/06/0f332b7b988f0faf665bdcfe5b7b975da3cdb4be2d9aa5d13431fe88153b/kurde-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "45dc30224bbfbd3001b0ab0fdc56fe989d1fdfdd2ec83c2f4588120705441983",
"md5": "8d4a1f1e751dd910199d21421418dc66",
"sha256": "e9c663e838488a2fdcb18a075d14b577282e17baccb55b5e485ded41e1bfd272"
},
"downloads": -1,
"filename": "kurde-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "8d4a1f1e751dd910199d21421418dc66",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 3642,
"upload_time": "2023-10-27T00:08:21",
"upload_time_iso_8601": "2023-10-27T00:08:21.041214Z",
"url": "https://files.pythonhosted.org/packages/45/dc/30224bbfbd3001b0ab0fdc56fe989d1fdfdd2ec83c2f4588120705441983/kurde-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-27 00:08:21",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "kurde"
}