kaptan
======
|pypi| |docs| |build-status| |coverage| |license|
configuration parser.
installation
------------
.. code-block:: console
$ pip install kaptan
Also available as a package on FreeBSD, Debian, Arch Linux and Slackware.
usage
-----
**supported handlers**
- dict
- json
- yaml
- .ini
- python file
**default (dict) handler**
.. code-block:: python
config = kaptan.Kaptan()
config.import_config({
'environment': 'DEV',
'redis_uri': 'redis://localhost:6379/0',
'debug': False,
'pagination': {
'per_page': 10,
'limit': 20,
}
})
print config.get("pagination.limit")
# output: 20
**json handler**
.. code-block:: python
config = kaptan.Kaptan(handler="json")
config.import_config('{"everything": 42}')
print config.get("everything")
# output: 42
**yaml handler**
.. code-block:: python
config = kaptan.Kaptan(handler="yaml")
config.import_config("""
product:
price:
value: 12.65
currency_list:
1. TL
2. EURO
""")
print config.get("product.price.currency_list.0")
# output: TL
or you can get from directly from the filename:
``config.import_config("configuration.yaml")``
**.ini handler**
config.ini
.. code-block:: ini
[development]
database_uri = mysql://root:123456@localhost/posts
[production]
database_uri = mysql://poor_user:poor_password@localhost/poor_posts
.. code-block:: python
config = kaptan.Kaptan(handler="ini")
config.import_config('config.ini')
print config.get("production.database_uri")
# output: mysql://poor_user:poor_password@localhost/poor_posts
**file handler**
config.py
.. code-block:: python
DATABASE = 'mysql://root:123456@localhost/posts'
DEBUG = False
PAGINATION = {
'per_page': 10,
'limit': 20,
}
.. code-block:: python
config = kaptan.Kaptan(handler="file")
config.import_config('config')
print config.get("DEBUG")
# output: False
exporting configuration
-----------------------
.. code-block:: python
config = kaptan.Kaptan(handler="file")
config.import_config({
'environment': 'DEV',
'redis_uri': 'redis://localhost:6379/0',
'debug': False,
'pagination': {
'per_page': 10,
'limit': 20,
}
})
print config.export("yaml")
**output**:
.. code-block:: yaml
debug: false
environment: DEV
pagination: {limit: 20, per_page: 10}
redis_uri: redis://localhost:6379/0
``print config.export("json")``
outputs unindented json. ``.export`` accepts kwargs which pass into
`json.dumps`.
.. _json.dumps: http://docs.python.org/2/library/json.html#json.dump
.. code-block:: python
print config.export("json", indent=4)
**output**:
.. code-block:: json
{
"environment": "DEV",
"debug": false,
"pagination": {
"per_page": 10,
"limit": 20
},
"redis_uri": "redis://localhost:6379/0"
}
``config.export('yaml')`` also supports the `kwargs for pyyaml`_.
.. _kwargs for pyyaml: http://pyyaml.org/wiki/PyYAMLDocumentation#Dumper
New in Version 0.5.7: ``config.export('yaml', safe=True)`` will use ``.safe_dump``.
cli
---
exporting (defaults to json)
.. code-block:: console
$ echo "environment: DEV" > config.yaml
$ kaptan config.yaml --export json > config.json
$ cat config.json
{"environment": "DEV"}
getting a value
.. code-block:: console
$ kaptan config.yaml --key environment
DEV
specifying the handler
.. code-block:: console
$ mv config.yaml config.settings
$ kaptan config.settings:yaml --export json
{"environment": "DEV"}
config from stdin
.. code-block:: console
$ echo '{"source": "stdin"}' | kaptan -
{"source": "stdin"}
$ echo 'source: stdin' | kaptan -:yaml
{"source": "stdin"}
merging configs
.. code-block:: console
$ echo "environment: PROD" > config.settings
$ echo '{"source": "stdin"}' | kaptan - config.json config.settings:yaml
{"environment": "PROD", "source": "stdin"}
setting default handler
.. code-block:: console
$ echo "source: stdin" | kaptan --handler yaml - config.settings
{"environment": "PROD", "source": "stdin"}
writing json with yaml
.. code-block:: console
$ kaptan -:yaml -e json
<type yaml here>
<Ctrl + D>
<get json here>
running tests
-------------
with ``py.test``:
.. code-block:: console
$ py.test
contributors
------------
- `Cenk Altı <http://github.com/cenkalti>`_
- `Wesley Bitter <http://github.com/Wessie>`_
- `Mark Steve <http://github.com/marksteve>`_
- `Tony Narlock <http://github.com/tony>`_
- `Berker Peksag <http://github.com/berkerpeksag>`_
- `Pradyun S. Gedam <https://github.com/pradyunsg>`_
see more at https://github.com/emre/kaptan/graphs/contributors.
.. |pypi| image:: https://img.shields.io/pypi/v/kaptan.svg
:alt: Python Package
:target: http://badge.fury.io/py/kaptan
.. |build-status| image:: https://github.com/emre/kaptan/actions/workflows/tests.yml/badge.svg
:alt: Build Status
:target: https://github.com/emre/kaptan/actions/workflows/tests.yml
.. |coverage| image:: https://codecov.io/gh/emre/kaptan/branch/master/graph/badge.svg
:alt: Code Coverage
:target: https://codecov.io/gh/emre/kaptan
.. |license| image:: https://img.shields.io/github/license/emre/kaptan.svg
:alt: License
.. |docs| image:: https://readthedocs.org/projects/kaptan/badge/?version=latest
:alt: Documentation Status
:scale: 100%
:target: https://readthedocs.org/projects/kaptan/
Raw data
{
"_id": null,
"home_page": "https://github.com/emre/kaptan",
"name": "kaptan",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Emre Yilmaz",
"author_email": "mail@emreyilmaz.me",
"download_url": "https://files.pythonhosted.org/packages/ca/c8/3569c90535df1b7c6079c75b7fd3f304d6ec8ee1626855d37ca137409ba2/kaptan-0.6.0.tar.gz",
"platform": null,
"description": "kaptan\n======\n\n|pypi| |docs| |build-status| |coverage| |license|\n\nconfiguration parser.\n\ninstallation\n------------\n\n.. code-block:: console\n\n $ pip install kaptan\n\nAlso available as a package on FreeBSD, Debian, Arch Linux and Slackware.\n\nusage\n-----\n\n**supported handlers**\n\n- dict\n- json\n- yaml\n- .ini\n- python file\n\n**default (dict) handler**\n\n.. code-block:: python\n\n config = kaptan.Kaptan()\n config.import_config({\n 'environment': 'DEV',\n 'redis_uri': 'redis://localhost:6379/0',\n 'debug': False,\n 'pagination': {\n 'per_page': 10,\n 'limit': 20,\n }\n })\n\n print config.get(\"pagination.limit\")\n\n # output: 20\n\n**json handler**\n\n.. code-block:: python\n\n config = kaptan.Kaptan(handler=\"json\")\n config.import_config('{\"everything\": 42}')\n\n print config.get(\"everything\")\n # output: 42\n\n**yaml handler**\n\n.. code-block:: python\n\n config = kaptan.Kaptan(handler=\"yaml\")\n config.import_config(\"\"\"\n product:\n price:\n value: 12.65\n currency_list:\n 1. TL\n 2. EURO\n \"\"\")\n print config.get(\"product.price.currency_list.0\")\n # output: TL\n\nor you can get from directly from the filename:\n\n``config.import_config(\"configuration.yaml\")``\n\n**.ini handler**\n\nconfig.ini\n\n.. code-block:: ini\n\n [development]\n database_uri = mysql://root:123456@localhost/posts\n\n [production]\n database_uri = mysql://poor_user:poor_password@localhost/poor_posts\n\n.. code-block:: python\n\n config = kaptan.Kaptan(handler=\"ini\")\n config.import_config('config.ini')\n\n print config.get(\"production.database_uri\")\n # output: mysql://poor_user:poor_password@localhost/poor_posts\n\n**file handler**\n\nconfig.py\n\n.. code-block:: python\n\n DATABASE = 'mysql://root:123456@localhost/posts'\n DEBUG = False\n PAGINATION = {\n 'per_page': 10,\n 'limit': 20,\n }\n\n.. code-block:: python\n\n config = kaptan.Kaptan(handler=\"file\")\n config.import_config('config')\n\n print config.get(\"DEBUG\")\n # output: False\n\nexporting configuration\n-----------------------\n\n.. code-block:: python\n\n config = kaptan.Kaptan(handler=\"file\")\n config.import_config({\n 'environment': 'DEV',\n 'redis_uri': 'redis://localhost:6379/0',\n 'debug': False,\n 'pagination': {\n 'per_page': 10,\n 'limit': 20,\n }\n })\n\n print config.export(\"yaml\")\n\n**output**:\n\n.. code-block:: yaml\n\n debug: false\n environment: DEV\n pagination: {limit: 20, per_page: 10}\n redis_uri: redis://localhost:6379/0\n\n``print config.export(\"json\")``\n\noutputs unindented json. ``.export`` accepts kwargs which pass into\n`json.dumps`.\n\n.. _json.dumps: http://docs.python.org/2/library/json.html#json.dump\n\n.. code-block:: python\n\n print config.export(\"json\", indent=4)\n\n**output**:\n\n.. code-block:: json\n\n {\n \"environment\": \"DEV\",\n \"debug\": false,\n \"pagination\": {\n \"per_page\": 10,\n \"limit\": 20\n },\n \"redis_uri\": \"redis://localhost:6379/0\"\n }\n\n``config.export('yaml')`` also supports the `kwargs for pyyaml`_.\n\n.. _kwargs for pyyaml: http://pyyaml.org/wiki/PyYAMLDocumentation#Dumper\n\nNew in Version 0.5.7: ``config.export('yaml', safe=True)`` will use ``.safe_dump``.\n\ncli\n---\n\nexporting (defaults to json)\n\n.. code-block:: console\n\n $ echo \"environment: DEV\" > config.yaml\n $ kaptan config.yaml --export json > config.json\n $ cat config.json\n {\"environment\": \"DEV\"}\n\ngetting a value\n\n.. code-block:: console\n\n $ kaptan config.yaml --key environment\n DEV\n\nspecifying the handler\n\n.. code-block:: console\n\n $ mv config.yaml config.settings\n $ kaptan config.settings:yaml --export json\n {\"environment\": \"DEV\"}\n\nconfig from stdin\n\n.. code-block:: console\n\n $ echo '{\"source\": \"stdin\"}' | kaptan -\n {\"source\": \"stdin\"}\n $ echo 'source: stdin' | kaptan -:yaml\n {\"source\": \"stdin\"}\n\nmerging configs\n\n.. code-block:: console\n\n $ echo \"environment: PROD\" > config.settings\n $ echo '{\"source\": \"stdin\"}' | kaptan - config.json config.settings:yaml\n {\"environment\": \"PROD\", \"source\": \"stdin\"}\n\nsetting default handler\n\n.. code-block:: console\n\n $ echo \"source: stdin\" | kaptan --handler yaml - config.settings\n {\"environment\": \"PROD\", \"source\": \"stdin\"}\n\nwriting json with yaml\n\n.. code-block:: console\n\n $ kaptan -:yaml -e json\n <type yaml here>\n <Ctrl + D>\n <get json here>\n\nrunning tests\n-------------\n\nwith ``py.test``:\n\n.. code-block:: console\n\n $ py.test\n\ncontributors\n------------\n\n- `Cenk Alt\u0131 <http://github.com/cenkalti>`_\n- `Wesley Bitter <http://github.com/Wessie>`_\n- `Mark Steve <http://github.com/marksteve>`_\n- `Tony Narlock <http://github.com/tony>`_\n- `Berker Peksag <http://github.com/berkerpeksag>`_\n- `Pradyun S. Gedam <https://github.com/pradyunsg>`_\n\nsee more at https://github.com/emre/kaptan/graphs/contributors.\n\n.. |pypi| image:: https://img.shields.io/pypi/v/kaptan.svg\n :alt: Python Package\n :target: http://badge.fury.io/py/kaptan\n\n.. |build-status| image:: https://github.com/emre/kaptan/actions/workflows/tests.yml/badge.svg\n :alt: Build Status\n :target: https://github.com/emre/kaptan/actions/workflows/tests.yml\n\n.. |coverage| image:: https://codecov.io/gh/emre/kaptan/branch/master/graph/badge.svg\n :alt: Code Coverage\n :target: https://codecov.io/gh/emre/kaptan\n\n.. |license| image:: https://img.shields.io/github/license/emre/kaptan.svg\n :alt: License \n\n.. |docs| image:: https://readthedocs.org/projects/kaptan/badge/?version=latest\n :alt: Documentation Status\n :scale: 100%\n :target: https://readthedocs.org/projects/kaptan/\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Configuration manager",
"version": "0.6.0",
"project_urls": {
"Homepage": "https://github.com/emre/kaptan"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "77264e7fa0e03e8bac6fc489f11f4bddfcf0174f725bc19e72609219ab44ca1f",
"md5": "b3edf44d4da2ae12a46a7e6b7c227e5b",
"sha256": "05b6a3d9eb4c4e53173519491cf32847a56d923226145938f1ffce547e4eac27"
},
"downloads": -1,
"filename": "kaptan-0.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b3edf44d4da2ae12a46a7e6b7c227e5b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 11032,
"upload_time": "2023-08-27T11:24:03",
"upload_time_iso_8601": "2023-08-27T11:24:03.318990Z",
"url": "https://files.pythonhosted.org/packages/77/26/4e7fa0e03e8bac6fc489f11f4bddfcf0174f725bc19e72609219ab44ca1f/kaptan-0.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cac83569c90535df1b7c6079c75b7fd3f304d6ec8ee1626855d37ca137409ba2",
"md5": "2d3b4256cface38bf9bd6c2d871da493",
"sha256": "101330a44fdede888586f3010bd145c0ec48a4806bc56429fa5487a6774021f8"
},
"downloads": -1,
"filename": "kaptan-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "2d3b4256cface38bf9bd6c2d871da493",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11861,
"upload_time": "2023-08-27T11:24:04",
"upload_time_iso_8601": "2023-08-27T11:24:04.620800Z",
"url": "https://files.pythonhosted.org/packages/ca/c8/3569c90535df1b7c6079c75b7fd3f304d6ec8ee1626855d37ca137409ba2/kaptan-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-27 11:24:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "emre",
"github_project": "kaptan",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "kaptan"
}