{ "info": { "author": "Platform.sh", "author_email": "sayhello@platform.sh", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only" ], "description": "# Platform.sh Config Reader (Python)\n\n[![CircleCI Status](https://circleci.com/gh/platformsh/config-reader-python.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/platformsh/config-reader-python)\n\nThis library provides a streamlined and easy to use way to interact with a Platform.sh environment. It offers utility methods to access routes and relationships more cleanly than reading the raw environment variables yourself.\n\nThis library requires Python 3.5 or later.\n\n## Install\n\n```bash\npip install platformshconfig\n```\n\n## Usage Example\n\nExample:\n\n```python\nimport sys\nimport pysolr\n\nfrom platformshconfig import Config\n\n\nconfig = Config()\n\nif not config.is_valid_platform():\n sys.exit(\"Not in a Platform.sh Environment.\")\n\ncredentials = config.credentials('solr')\n\nformatted = config.formatted_credentials('solr', 'pysolr')\n\nconn = pysolr.Solr(formatted)\n\n# Do stuff with the conn here.\n```\n\n## API Reference\n\n### Create a config object\n\n```python\nfrom platformshconfig import Config\n\nconfig = Config()\n```\n\n`config` is now a `Config` object that provides access to the Platform.sh environment.\n\nThe `is_valid_platform()` method returns `True` if the code is running in a context that has Platform.sh environment variables defined. If it returns `False` then most other functions will throw exceptions if used.\n\n### Inspect the environment\n\nThe following methods return `True` or `False` to help determine in what context the code is running:\n\n```python\nconfig.in_build()\n\nconfig.in_runtime()\n\nconfig.on_enterprise()\n\nconfig.on_production()\n```\n\n### Read environment variables\n\nThe following magic properties return the corresponding environment variable value. See the [Platform.sh documentation](https://docs.platform.sh/development/variables.html) for a description of each.\n\nThe following are available both in Build and at Runtime:\n\n```python\nconfig.applicationName\n\nconfig.appDir\n\nconfig.project\n\nconfig.treeID\n\nconfig.projectEntropy\n```\n\nThe following are available only if `in_runtime()` returned `True`:\n\n```python\nconfig.branch\n\ncondig.documentRoot\n\nconfig.smtpHost\n\nconfig.environment\n\nconfig.socket\n\nconfig.port\n```\n\n### Reading service credentials\n\n[Platform.sh services](https://docs.platform.sh/configuration/services.html) are defined in a `services.yaml` file, and exposed to an application by listing a `relationship` to that service in the application's `.platform.app.yaml` file. User, password, host, etc. information is then exposed to the running application in the `PLATFORM_RELATIONSHIPS` environment variable, which is a base64-encoded JSON string. The following method allows easier access to credential information than decoding the environment variable yourself.\n\n```python\ncreds = config.credentials('database')\n```\n\nThe return value of `credentials()` is a dictionary matching the relationship JSON object, which includes the appropriate user, password, host, database name, and other pertinent information. See the [Service documentation](https://docs.platform.sh/configuration/services.html) for your service for the exact structure and meaning of each property. In most cases that information can be passed directly to whatever other client library is being used to connect to the service.\n\n## Formatting service credentials\n\nIn some cases the library being used to connect to a service wants its credentials formatted in a specific way; it could be a DSN string of some sort or it needs certain values concatenated to the database name, etc. For those cases you can use \"Credential Formatters\". A Credential Formatter is any `callable` (function, anonymous function, object method, etc.) that takes a credentials array and returns any type, since the library may want different types.\n\nCredential Formatters can be registered on the configuration object, and a few are included out of the box. That allows 3rd party libraries to ship their own formatters that can be easily integrated into the `Config` object to allow easier use.\n\n```python\ndef format_my_service(credentials):\n return \"some string based on 'credentials'.\"\n\n# Call this in setup\nconfig.register_formatter('my_service', format_my_service)\n\n# Then call this method to get the formatted version\nformatted = config.formatted_credentials('database', 'my_service')\n```\n\nThe first parameter is the name of a relationship defined in `.platform.app.yaml`. The second is a formatter that was previously registered with `register_formatter()`. If either the service or formatter is missing an exception will be thrown. The type of `formatted` will depend on the formatter function and can be safely passed directly to the client library.\n\nThree formatters are included out of the box:\n\n* `pymongo` returns a DSN appropriate for using `pymongo` to connect to MongoDB. Note that `pymongo` will still need the username and password from the credentials dictionary passed as separate parameters.\n* `pysolr` returns a DSN appropriate for using `pysolr` to connect to Apache Solr.\n* `postgresql_dsn` returns a DSN appropriate for postgresql connection.\n\n### Reading Platform.sh variables\n\nPlatform.sh allows you to define arbitrary variables that may be available at build time, runtime, or both. They are stored in the `PLATFORM_VARIABLES` environment variable, which is a base64-encoded JSON string. \n\nThe following two methods allow access to those values from your code without having to bother decoding the values yourself:\n\n```python\nconfig.variables()\n```\n\nThis method returns a dictionary of all variables defined. Usually this method is not necessary and `config.variable()` is preferred.\n\n```python\nconfig.variable(\"foo\", \"default\")\n```\n\nThis method looks for the \"foo\" variable. If found, it is returned. If not, the optional second parameter is returned as a default.\n\n### Reading Routes\n\n[Routes](https://docs.platform.sh/configuration/routes.html) on Platform.sh define how a project will handle incoming requests; that primarily means what application container will serve the request, but it also includes cache configuration, TLS settings, etc. Routes may also have an optional ID, which is the preferred way to access them.\n\n```python\nconfig.route(\"main\")\n```\n\nThe `route()` method takes a single string for the route ID (\"main\" in this case) and returns the corresponding route array. If the route is not found it will throw an exception.\n\nTo access all routes, or to search for a route that has no ID, the `routes()` method returns an dictionary of routes keyed by their URL. That mirrors the structure of the `PLATFORM_ROUTES` environment variable.\n\nIf called in the build phase an exception is thrown.\n\n\n# Version History\n\n## Unreleased\n\n* **Improvements**\n\n* **Fixes**\n\n* **Misc.**\n\n## v0.1.0 (2010-02-14)\n\n- Initial version.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/platformsh/config-reader-python3", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "platformshconfig", "package_url": "https://pypi.org/project/platformshconfig/", "platform": "", "project_url": "https://pypi.org/project/platformshconfig/", "project_urls": { "Homepage": "https://github.com/platformsh/config-reader-python3" }, "release_url": "https://pypi.org/project/platformshconfig/2.3.0/", "requires_dist": null, "requires_python": "", "summary": "Small helper to access Platform.sh environment variables.", "version": "2.3.0" }, "last_serial": 5857122, "releases": { "2.0.0": [ { "comment_text": "", "digests": { "md5": "6052452ea5128d8d857f5952528233ae", "sha256": "864c782c1d7c7cb0474c72d2ecb80ce0fe17f620591f40c9edc2a04ec93323a2" }, "downloads": -1, "filename": "platformshconfig-2.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "6052452ea5128d8d857f5952528233ae", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9512, "upload_time": "2019-03-05T19:43:37", "url": "https://files.pythonhosted.org/packages/86/ad/b2c38fce32de1bfb3575e736cfe14e4b4d3b1b3779d4a3a6451c3da363ea/platformshconfig-2.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "10ecc3076c43da978fea12a17025c4c4", "sha256": "edd45069b1defd08a39f79afd4002ea6cf5af43059e21ba6d9f692fc4a8f1f69" }, "downloads": -1, "filename": "platformshconfig-2.0.0.tar.gz", "has_sig": false, "md5_digest": "10ecc3076c43da978fea12a17025c4c4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11512, "upload_time": "2019-03-05T19:43:39", "url": "https://files.pythonhosted.org/packages/c8/31/57c4f84b8eec71556fe8e0520bb53f2b4bcf8b63ec54704b1b39f1b96727/platformshconfig-2.0.0.tar.gz" } ], "2.0.4": [ { "comment_text": "", "digests": { "md5": "ef5e6af9cdbafa54f369071c40701a19", "sha256": "c50fbafd84fb298eb3683e896e2553868b57c939d6eca2e9ab6ceb72b770b706" }, "downloads": -1, "filename": "platformshconfig-2.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "ef5e6af9cdbafa54f369071c40701a19", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9510, "upload_time": "2019-03-06T19:13:55", "url": "https://files.pythonhosted.org/packages/e1/25/4e2ecc10210b2b95431bd873c4cdef53d45dc8a25cb4fb53521401638a66/platformshconfig-2.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f5a0b0a14666f86620adebf6ab1fcca4", "sha256": "8404cfb4fb7d14dfda0a8a87d7358db84e5dfcb922fa8f1b96c4cc52ca082262" }, "downloads": -1, "filename": "platformshconfig-2.0.4.tar.gz", "has_sig": false, "md5_digest": "f5a0b0a14666f86620adebf6ab1fcca4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13101, "upload_time": "2019-03-06T19:13:57", "url": "https://files.pythonhosted.org/packages/7a/8f/5fb76f434d2061a6597ada9b50dd382a22f5a0ed95176dfa9b2583eed5f8/platformshconfig-2.0.4.tar.gz" } ], "2.1.1": [ { "comment_text": "", "digests": { "md5": "504ceadfab59fc58f0718c4557494f32", "sha256": "62437259baedc252aa3e75332e96c3d64722f6b7899cba56f70cae47fbc4b4a4" }, "downloads": -1, "filename": "platformshconfig-2.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "504ceadfab59fc58f0718c4557494f32", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9644, "upload_time": "2019-03-25T17:26:59", "url": "https://files.pythonhosted.org/packages/af/0f/b06786d024eee67e966b998db3270bd2f5ae9760f4ddd5a14764b36a24e0/platformshconfig-2.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "58c757a10d6f0ac559ad09532807266a", "sha256": "a6df06ed3c099bfc0a87d6633f1658dddf687cfae15283566a3e1e9791801ac6" }, "downloads": -1, "filename": "platformshconfig-2.1.1.tar.gz", "has_sig": false, "md5_digest": "58c757a10d6f0ac559ad09532807266a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11129, "upload_time": "2019-03-25T17:27:00", "url": "https://files.pythonhosted.org/packages/3e/6b/88117df23df0d8890bfcd37722173651b7c9bcc22f9b7953a440e6b62135/platformshconfig-2.1.1.tar.gz" } ], "2.2.0": [ { "comment_text": "", "digests": { "md5": "9de8ad58dfdfffa9bf1e34724acfda06", "sha256": "0132915986a2ae4f14a12e3d1580dd4e53c441cb4b45a7d6fd445b43fb92ff16" }, "downloads": -1, "filename": "platformshconfig-2.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "9de8ad58dfdfffa9bf1e34724acfda06", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9875, "upload_time": "2019-04-24T21:58:47", "url": "https://files.pythonhosted.org/packages/13/e2/c60bb8a8b5e44128ac05ab01448beaa4fa5b5e3ad2023b6fffb888b50bc2/platformshconfig-2.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2bedb12cdd06071672f5501933e85b52", "sha256": "1532423582bb412872a84b71f3c8ef302dfcffeaefdd768aec35d6bb538fcb57" }, "downloads": -1, "filename": "platformshconfig-2.2.0.tar.gz", "has_sig": false, "md5_digest": "2bedb12cdd06071672f5501933e85b52", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11370, "upload_time": "2019-04-24T21:58:49", "url": "https://files.pythonhosted.org/packages/2e/44/446f364f2e3f0f5c39c5e484e37ad97dbc5d941106d441e256be11232c8f/platformshconfig-2.2.0.tar.gz" } ], "2.2.1": [ { "comment_text": "", "digests": { "md5": "c821b5e556de72b703d36574456c8f8e", "sha256": "c94666798e9259f6cf53101f1320b6f2318e553f9beb69cb883b599b6045c87d" }, "downloads": -1, "filename": "platformshconfig-2.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "c821b5e556de72b703d36574456c8f8e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9812, "upload_time": "2019-04-25T21:55:57", "url": "https://files.pythonhosted.org/packages/a4/59/1b3a4a63597fa4ee8215753bf1b12c069fb7d937f9a6daec7fc5605c1b38/platformshconfig-2.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "32db5a95923c797e581744516487801b", "sha256": "1567cf3ed6c107f9c3a230276c299b8fc1879e3f3e957eaf1aacda40bbed35cc" }, "downloads": -1, "filename": "platformshconfig-2.2.1.tar.gz", "has_sig": false, "md5_digest": "32db5a95923c797e581744516487801b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13762, "upload_time": "2019-04-25T21:55:59", "url": "https://files.pythonhosted.org/packages/ad/34/3b9c528cc7874db17eff516378a68c878b389e41e5d06f9933385736d374/platformshconfig-2.2.1.tar.gz" } ], "2.2.3": [ { "comment_text": "", "digests": { "md5": "2a373b1755fd72ba10b803bb604c28bd", "sha256": "d285702d2c1344fa1ae333356ae717fe102c7ac7cf61edd15d294e56e004839a" }, "downloads": -1, "filename": "platformshconfig-2.2.3-py3-none-any.whl", "has_sig": false, "md5_digest": "2a373b1755fd72ba10b803bb604c28bd", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9848, "upload_time": "2019-04-30T16:10:07", "url": "https://files.pythonhosted.org/packages/8c/77/b8ce55f73187b8b46b8f4766196df4638abbc4307a3c9d4e1ec30a1a9edb/platformshconfig-2.2.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d8e05303fb15d72ce45612a5b228ca4d", "sha256": "effa9e10ac22cd641f0f4f618eb4c02307a43caa1b7c6dda86b3344bcd246f3d" }, "downloads": -1, "filename": "platformshconfig-2.2.3.tar.gz", "has_sig": false, "md5_digest": "d8e05303fb15d72ce45612a5b228ca4d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11388, "upload_time": "2019-04-30T16:10:10", "url": "https://files.pythonhosted.org/packages/17/02/8a2e9ad6637873aa10bc3b42c7158c4165c5846e6ce5f6820d13d7b764f6/platformshconfig-2.2.3.tar.gz" } ], "2.3.0": [ { "comment_text": "", "digests": { "md5": "5470ebd48cd53a617697c0ce2f7e9131", "sha256": "8d259958040b1e9cf1cac9d2fd4628f3566964ecc398d1830c7cf1c572dff8f2" }, "downloads": -1, "filename": "platformshconfig-2.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "5470ebd48cd53a617697c0ce2f7e9131", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10356, "upload_time": "2019-09-19T15:23:06", "url": "https://files.pythonhosted.org/packages/64/3b/1210aca239bc33779a5c6d3693847e5928a588bc595e86e5e59e73ffc6ae/platformshconfig-2.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "afb868417cbd7ee77ad97beefae2a2a3", "sha256": "e184bad25292c5e2dfaf3ddfcb6d0f83a7add0a8347520fdb69305b2206e8f6e" }, "downloads": -1, "filename": "platformshconfig-2.3.0.tar.gz", "has_sig": false, "md5_digest": "afb868417cbd7ee77ad97beefae2a2a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11907, "upload_time": "2019-09-19T15:23:08", "url": "https://files.pythonhosted.org/packages/1b/f4/24ee5c5e639be98d717b76c047005aa97d395c0e7a17628179236247e1bd/platformshconfig-2.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5470ebd48cd53a617697c0ce2f7e9131", "sha256": "8d259958040b1e9cf1cac9d2fd4628f3566964ecc398d1830c7cf1c572dff8f2" }, "downloads": -1, "filename": "platformshconfig-2.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "5470ebd48cd53a617697c0ce2f7e9131", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10356, "upload_time": "2019-09-19T15:23:06", "url": "https://files.pythonhosted.org/packages/64/3b/1210aca239bc33779a5c6d3693847e5928a588bc595e86e5e59e73ffc6ae/platformshconfig-2.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "afb868417cbd7ee77ad97beefae2a2a3", "sha256": "e184bad25292c5e2dfaf3ddfcb6d0f83a7add0a8347520fdb69305b2206e8f6e" }, "downloads": -1, "filename": "platformshconfig-2.3.0.tar.gz", "has_sig": false, "md5_digest": "afb868417cbd7ee77ad97beefae2a2a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11907, "upload_time": "2019-09-19T15:23:08", "url": "https://files.pythonhosted.org/packages/1b/f4/24ee5c5e639be98d717b76c047005aa97d395c0e7a17628179236247e1bd/platformshconfig-2.3.0.tar.gz" } ] }