YASCP
=====
This is Yet Another Simple Configuration Parser module for INI style configurations files.
Installation
------------
``pip install yascp``
``easy_install yascp``
USAGE
-----
A sample configuration is looking like this and is saved in file called example.conf:
::
[database]
login = user
password = topsecret
host = example.com
port = 3306
[backend_api]
login = api_user
password = api_password
url = http://example.com:9080
In scripts
^^^^^^^^^^
The constructor takes only two arguments - first one is the name or absolute path to the configuration file (see below "Configuration File" for more details on this) and a dictionary of default values which will be parsed before any actual configuration file is read. If same section and option is found in a configuration file then the default will be overwritten.
Until version 0.2.6 KEY and VALUE could be separated by the '=' sign only but from 2.7 third argument may be passed on to specify the delimiter and it can be anything. Default is still '=' if not specified.
::
import yascp
config = yascp.parser.Parser(configuration_file_name = 'example.conf', defaults = {'extra.port':'666'}, delimiter = '=')
login = config.database.username
password = config.database.password
host = config.database.host
port = config.database.port
print config.backend_api.url
print config.extra.port
There is a convenience method available to print off all of the configuration parsed.
So running:
::
config.print_all()
would print to the screen following:
::
backend_api.url = http://example.com:9080
backend_api.password = api_password
backend_api.login = api_user
extra.port = 666
database.host = example.com
database.port = 3306
database.login = user
database.password = topsecret
**Notice**: *Everything is a string. The module does not distinguish any type of data and so the developer should know where an integer for example is expected an perform all required tests/handle possible errors.*
In command line
^^^^^^^^^^^^^^^
::
yascp_parser.py [full path to or name of an INI config file] [section.option to be fetched|--print-all]
The script takes two arguments
The first argument is the name of a configuration file or full path to one (see below for "Configuration File" section for more details).
The second argument may be "--list-all" to obtain a list of all available options
or a key of specific option to get value for this option only (run first with
"--list-all" to see what exactly can be used here).
If an option doesn't belong to any of the sections in the configuration file
then it should be addresses with "default" section, i.e:
::
default.[myoption]
Sample usage:
::
python parser.py /tmp/example.conf --print-all
backend_api.url = http://example.com:9080
backend_api.password = api_password
backend_api.login = api_user
database.host = example.com
database.port = 3306
database.login = user
database.password = topsecret
Knowing now what options are avaialbe you can fetch only this that you need:
::
python parser.py /tmp/example.conf backend_api.url
http://example.com:9080
Configuration File
------------------
If absolute path is provided to a configuration file then only that file is read but
if only a name of configuration file is given then the script will attempt to read
a file by that name in following locations and order:
#. /etc/[config file name]
#. ~/[config file name]
#. Directory from which the script has been ran.
**Notice**: If more than one configuration file is present then the duplicated options set for example in a configuration file saved in /etc/ will be overwritten by those in user's home directory and so on.
Changelog
---------
0.3.2
^^^^^
- Fixing some minor errors, reformatting, moving away from Python 2 no further
compatibility can be guaranteed
0.3.1
^^^^^
- Python 2 & 3 compatibility added
0.3.0
^^^^^
- fixed issue with "print_all" method where if user overwritten one value with anything else than string it would break
- corrected number of code style issues (too long lines, etc.) in Parser module
0.2.9
^^^
- configuration parsing errors are now caught if invoked from command line so no trace is printed
- '~' is now expanded to user's home directory if Parser is initialized from within external Python code
- minor spelling corrections
0.2.8
^^^
- minor spelling corrections, documentation corrections/updates
0.2.7
^^^
- extended functionality - now a delimiter can be passed on when used as a module so from now on KEY and VALUE can be separated by = as usual but also space character, tab character or anything else
0.2.6
^^^
- fixed a "hidden" issue with infinite recursion within __getattr__ method; this didn't affect the functionality though
0.2.5
^^^
- introduced proper access point from shell via script **yascp_parser.py** (available from PATH after installation)
- introduced possibility to execute the module by a direct call, i.e. **python -m yascp**
Raw data
{
"_id": null,
"home_page": "https://pypi.python.org/pypi/yascp/",
"name": "yascp",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "configuration,parse,parser,ini,yascp",
"author": "Miroslaw Janiewicz",
"author_email": "miroslaw.janiewicz@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b0/f6/04442ad57902651ac81239cf839eb7ec89921482e24924cd15dc77b12a09/yascp-0.3.2.tar.gz",
"platform": null,
"description": "YASCP\n=====\n\nThis is Yet Another Simple Configuration Parser module for INI style configurations files.\n\nInstallation\n------------\n\n``pip install yascp``\n\n``easy_install yascp``\n\nUSAGE\n-----\n\nA sample configuration is looking like this and is saved in file called example.conf:\n\n::\n\n [database]\n login = user\n password = topsecret\n host = example.com\n port = 3306\n\n [backend_api]\n login = api_user\n password = api_password\n url = http://example.com:9080\n\nIn scripts\n^^^^^^^^^^\n\nThe constructor takes only two arguments - first one is the name or absolute path to the configuration file (see below \"Configuration File\" for more details on this) and a dictionary of default values which will be parsed before any actual configuration file is read. If same section and option is found in a configuration file then the default will be overwritten.\nUntil version 0.2.6 KEY and VALUE could be separated by the '=' sign only but from 2.7 third argument may be passed on to specify the delimiter and it can be anything. Default is still '=' if not specified.\n\n::\n\n import yascp\n config = yascp.parser.Parser(configuration_file_name = 'example.conf', defaults = {'extra.port':'666'}, delimiter = '=')\n\n login = config.database.username\n password = config.database.password\n host = config.database.host\n port = config.database.port\n\n print config.backend_api.url\n print config.extra.port\n\nThere is a convenience method available to print off all of the configuration parsed.\n\nSo running:\n::\n\n config.print_all()\n\nwould print to the screen following:\n\n::\n\n backend_api.url = http://example.com:9080\n backend_api.password = api_password\n backend_api.login = api_user\n extra.port = 666\n database.host = example.com\n database.port = 3306\n database.login = user\n database.password = topsecret\n\n\n**Notice**: *Everything is a string. The module does not distinguish any type of data and so the developer should know where an integer for example is expected an perform all required tests/handle possible errors.*\n\nIn command line\n^^^^^^^^^^^^^^^\n\n::\n\n yascp_parser.py [full path to or name of an INI config file] [section.option to be fetched|--print-all]\n\nThe script takes two arguments\n\nThe first argument is the name of a configuration file or full path to one (see below for \"Configuration File\" section for more details).\n\nThe second argument may be \"--list-all\" to obtain a list of all available options\nor a key of specific option to get value for this option only (run first with\n\"--list-all\" to see what exactly can be used here).\n\nIf an option doesn't belong to any of the sections in the configuration file\nthen it should be addresses with \"default\" section, i.e:\n\n::\n\n default.[myoption]\n\nSample usage:\n\n::\n\n python parser.py /tmp/example.conf --print-all\n backend_api.url = http://example.com:9080\n backend_api.password = api_password\n backend_api.login = api_user\n database.host = example.com\n database.port = 3306\n database.login = user\n database.password = topsecret\n\nKnowing now what options are avaialbe you can fetch only this that you need:\n\n::\n\n python parser.py /tmp/example.conf backend_api.url\n http://example.com:9080\n\nConfiguration File\n------------------\n\nIf absolute path is provided to a configuration file then only that file is read but\nif only a name of configuration file is given then the script will attempt to read\na file by that name in following locations and order:\n\n#. /etc/[config file name]\n#. ~/[config file name]\n#. Directory from which the script has been ran.\n\n**Notice**: If more than one configuration file is present then the duplicated options set for example in a configuration file saved in /etc/ will be overwritten by those in user's home directory and so on.\n\nChangelog\n---------\n0.3.2\n^^^^^\n- Fixing some minor errors, reformatting, moving away from Python 2 no further\n compatibility can be guaranteed \n\n0.3.1\n^^^^^\n- Python 2 & 3 compatibility added\n\n0.3.0\n^^^^^\n- fixed issue with \"print_all\" method where if user overwritten one value with anything else than string it would break\n- corrected number of code style issues (too long lines, etc.) in Parser module\n\n0.2.9\n^^^\n- configuration parsing errors are now caught if invoked from command line so no trace is printed\n- '~' is now expanded to user's home directory if Parser is initialized from within external Python code\n- minor spelling corrections\n\n0.2.8\n^^^\n- minor spelling corrections, documentation corrections/updates\n\n0.2.7\n^^^\n- extended functionality - now a delimiter can be passed on when used as a module so from now on KEY and VALUE can be separated by = as usual but also space character, tab character or anything else\n\n0.2.6\n^^^\n- fixed a \"hidden\" issue with infinite recursion within __getattr__ method; this didn't affect the functionality though\n\n0.2.5\n^^^\n- introduced proper access point from shell via script **yascp_parser.py** (available from PATH after installation)\n- introduced possibility to execute the module by a direct call, i.e. **python -m yascp**\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Yet Another Simple Configuration Parser for INI-style configuration files.",
"version": "0.3.2",
"project_urls": {
"Homepage": "https://pypi.python.org/pypi/yascp/"
},
"split_keywords": [
"configuration",
"parse",
"parser",
"ini",
"yascp"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ca8a68c111a20af4a439f038c99fd8c2026b91818e87d2b90156b0111cfdab5e",
"md5": "cd8033fb1ad6b97911d202c64e33d4f8",
"sha256": "182f5b534b2ca4856514aa8eb773f6d4e45ff3a54e50d5f57ab5e9c75d83aa26"
},
"downloads": -1,
"filename": "yascp-0.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cd8033fb1ad6b97911d202c64e33d4f8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 10412,
"upload_time": "2023-12-11T13:40:33",
"upload_time_iso_8601": "2023-12-11T13:40:33.749365Z",
"url": "https://files.pythonhosted.org/packages/ca/8a/68c111a20af4a439f038c99fd8c2026b91818e87d2b90156b0111cfdab5e/yascp-0.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b0f604442ad57902651ac81239cf839eb7ec89921482e24924cd15dc77b12a09",
"md5": "a820b5d2c2325ad311f3b72973cd43fe",
"sha256": "6b53456ae9e7b5d62c77d72e014fd710757827a18468e625f11904e13d13eb17"
},
"downloads": -1,
"filename": "yascp-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "a820b5d2c2325ad311f3b72973cd43fe",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10287,
"upload_time": "2023-12-11T13:40:36",
"upload_time_iso_8601": "2023-12-11T13:40:36.142035Z",
"url": "https://files.pythonhosted.org/packages/b0/f6/04442ad57902651ac81239cf839eb7ec89921482e24924cd15dc77b12a09/yascp-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-11 13:40:36",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "yascp"
}