# Aperol Config
Aperol is a featherweight framework for configuration of Python objects based on dependency injection.
## Usage
Requires Python >= 3.10.
Install Aperol from PyPI:
```bash
$ pip install aperol
```
Define a basic configuration file `dummy.yaml`:
```yaml
imports:
- random
a: -1
b.type: math.pi
c.type: uniform
d:
type: uniform()
a: 10
b: 11
```
Python objects are specified by the `type` keyword.
In the example above, `uniform` is resolved to the `random` module specified in the `imports` section.
On the other hand, `pi` is explicitly imported
from the `math` module.
Load the config file using Aperol and use the configured objects:
```python
>>> import random
>>> random.seed(0) # seed set for reproducibility
>>> import aperol
>>> configured = aperol.parse_config("dummy.yaml")
>>> configured["a"]
-1
>>> configured["b"]
3.141592653589793
>>> configured["c"]
_DelayedConstructor(factory=<bound method Random.uniform of <random.Random object at ...>>, init=False, kwargs={'a': -1, 'b': 3.141592653589793})
>>> configured["d"]
10.844421851525048
>>> uniform = configured["c"]
>>> uniform()
2.1391383869735945
>>> uniform()
0.7418361694776736
```
Package imports can be specified in one of three ways:
1. Within the config `imports` section,
2. passing `search_pkgs` to `aperol.parse_config`, or
3. registering imports globally with `aperol.register_imports`
In all three cases, each import must either be a string module name `"X.Y"` corresponding to `import X.Y`, or a tuple `("X.Y", "Z")` corresponding to `import X.Y as Z`.
Configuration file locations can be registered using `aperol.register_config_path`.
## Syntax
TODO (and TBC).
## Related
Aperol is inspired by [Gin Config](https://github.com/google/gin-config).
In comparison to Gin, Aperol allows configuration to be define using YAML (or any format which can be parsed to a nested dict tree). Thus it does not require learning a completely new syntax. Aperol is also simpler and does not provide all of the functionality of Gin; however, it is powerful enough to configure any Python object enabling flexible configuration.
Raw data
{
"_id": null,
"home_page": null,
"name": "aperol",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "aperol, config, configuration, machine, learning",
"author": null,
"author_email": "Ryan Eloff <ryaneloff@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e4/13/ead5e1a2f32e6065b33922875c6a276e57cf2c93d259301ba295e4e3f1f9/aperol-0.0.0a0.tar.gz",
"platform": null,
"description": "\n# Aperol Config\n\nAperol is a featherweight framework for configuration of Python objects based on dependency injection.\n\n## Usage\n\nRequires Python >= 3.10.\n\nInstall Aperol from PyPI:\n\n```bash\n$ pip install aperol\n```\n\nDefine a basic configuration file `dummy.yaml`:\n\n```yaml\nimports:\n - random\n\na: -1\nb.type: math.pi\nc.type: uniform\nd:\n type: uniform()\n a: 10\n b: 11\n```\n\nPython objects are specified by the `type` keyword.\nIn the example above, `uniform` is resolved to the `random` module specified in the `imports` section.\nOn the other hand, `pi` is explicitly imported\nfrom the `math` module.\n\nLoad the config file using Aperol and use the configured objects:\n\n```python\n>>> import random\n>>> random.seed(0) # seed set for reproducibility\n>>> import aperol\n>>> configured = aperol.parse_config(\"dummy.yaml\")\n>>> configured[\"a\"]\n-1\n>>> configured[\"b\"]\n3.141592653589793\n>>> configured[\"c\"]\n_DelayedConstructor(factory=<bound method Random.uniform of <random.Random object at ...>>, init=False, kwargs={'a': -1, 'b': 3.141592653589793})\n>>> configured[\"d\"]\n10.844421851525048\n>>> uniform = configured[\"c\"]\n>>> uniform()\n2.1391383869735945\n>>> uniform()\n0.7418361694776736\n```\n\nPackage imports can be specified in one of three ways:\n1. Within the config `imports` section,\n2. passing `search_pkgs` to `aperol.parse_config`, or\n3. registering imports globally with `aperol.register_imports`\n\nIn all three cases, each import must either be a string module name `\"X.Y\"` corresponding to `import X.Y`, or a tuple `(\"X.Y\", \"Z\")` corresponding to `import X.Y as Z`.\n\nConfiguration file locations can be registered using `aperol.register_config_path`.\n\n## Syntax\n\nTODO (and TBC).\n\n## Related\n\nAperol is inspired by [Gin Config](https://github.com/google/gin-config).\nIn comparison to Gin, Aperol allows configuration to be define using YAML (or any format which can be parsed to a nested dict tree). Thus it does not require learning a completely new syntax. Aperol is also simpler and does not provide all of the functionality of Gin; however, it is powerful enough to configure any Python object enabling flexible configuration.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Aperol: A featherweight framework for configuration of Python objects",
"version": "0.0.0a0",
"project_urls": {
"Homepage": "https://github.com/rpeloff/aperol",
"Repository": "https://github.com/rpeloff/aperol.git"
},
"split_keywords": [
"aperol",
" config",
" configuration",
" machine",
" learning"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9a0d434a80d560494a9fd16dfe7400c61d0f37152307c7a96825a0125bc2f808",
"md5": "0540f74c1577592ed3aa1db5d6b1ebc6",
"sha256": "bd44a34bde22c6a0ff68eb6734689d46602bb22bd8aa81b254cd2b555cec71c6"
},
"downloads": -1,
"filename": "aperol-0.0.0a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0540f74c1577592ed3aa1db5d6b1ebc6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 10537,
"upload_time": "2024-08-20T16:11:44",
"upload_time_iso_8601": "2024-08-20T16:11:44.672226Z",
"url": "https://files.pythonhosted.org/packages/9a/0d/434a80d560494a9fd16dfe7400c61d0f37152307c7a96825a0125bc2f808/aperol-0.0.0a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e413ead5e1a2f32e6065b33922875c6a276e57cf2c93d259301ba295e4e3f1f9",
"md5": "7d04deb0bdb970c671cdd8815ce85049",
"sha256": "aa2989252b7b1640941d3dcd388cf41b6d2aa90ceb0e6367b65d97d16ea3223e"
},
"downloads": -1,
"filename": "aperol-0.0.0a0.tar.gz",
"has_sig": false,
"md5_digest": "7d04deb0bdb970c671cdd8815ce85049",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 9971,
"upload_time": "2024-08-20T16:11:45",
"upload_time_iso_8601": "2024-08-20T16:11:45.879880Z",
"url": "https://files.pythonhosted.org/packages/e4/13/ead5e1a2f32e6065b33922875c6a276e57cf2c93d259301ba295e4e3f1f9/aperol-0.0.0a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-20 16:11:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rpeloff",
"github_project": "aperol",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "aperol"
}