{ "info": { "author": "Thomas Yager-Madden", "author_email": "yagermadden@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Environment :: Web Environment", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Database :: Front-Ends", "Topic :: Software Development :: Libraries", "Topic :: Utilities" ], "description": "\n# Nerium\n\n![small bicycle](https://dl.dropboxusercontent.com/s/7kba2cgrcvuj0hy/nerium-bicycle-sm.jpg \"Keeping the 'micro' in microservices\")\n\n[![CircleCI](https://img.shields.io/circleci/project/github/OAODEV/nerium.svg)](https://circleci.com/gh/OAODEV/nerium)\n[![Codecov](https://img.shields.io/codecov/c/github/OAODEV/nerium.svg)](https://codecov.io/gh/OAODEV/nerium)\n[![PyPI - Version](https://img.shields.io/pypi/v/nerium.svg)](https://pypi.org/project/nerium/)\n[![PyPI - License](https://img.shields.io/pypi/l/nerium.svg)](https://pypi.org/project/nerium/)\n[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/OAODEV/nerium)\n\nA lightweight [Responder](https://python-responder.org/)-based microservice that submits queries to a database and returns machine-readable serialized results (typically JSON). By analogy with static site generators, Nerium reads its queries and serialization formats from local files, stored on the filesystem. The idea is that report analysts should be able to write queries in their preferred local editor, and upload or mount them where Nerium can use them.\n\nOAO uses Nerium to easily and quickly provide JSON APIs with report results from our PostgreSQL data warehouse.\n\nNerium features an extendable architecture, allowing support for multiple query types and output formats.\n\nCurrently supports SQL queries using the excellent [Records](https://github.com/kennethreitz/records) library. In keeping with Records usage, query parameters can be specified in `key=value` format, and (_safely_!) injected into your query in `:key` format.\n\nIn theory, other query types can be added (under `nerium/resultset`) for non-SQL query languages. This is a promising area for future development.\n\nDefault JSON output represents `data` as an array of objects, one per result row, with database column names as keys. The default schema also provides top-level nodes for `name`, `metadata`, and `params` (details below). A `compact` JSON output format may also be requested, with separate `column` (array of column names) and `data` (array of row value arrays) nodes for compactness. Additional formats can be added by adding [marshmallow](https://marshmallow.readthedocs.io) schema definitions to `format_files`.\n\nNerium supports any backend that SQLAlchemy can, but since none of these are hard dependencies, drivers aren't included in Pipfile, and the Dockerfile only supports PostgreSQL. If you want Nerium to work with other databases, you can install Python connectors with `pip`, either in a virtualenv or by creating your own Dockerfile using `FROM oaodev/nerium`. (To ease installation, options for `nerium[mysql]` and `nerium[pg]` are provided in `setup.py`)\n\n## Install/Run\n\n### Using Docker\n\n```bash\n$ docker run -d --name=nerium \\\n--envfile=.env \\\n-v /local/path/to/query_files:/app/query_files \\\n-v /local/path/to/format_files:/app/format_files \\\n-p 5000:5000 oaodev/nerium\n\n$ curl http://localhost:5000/v1/?\n```\n\n### Local install\n\n```bash\npipenv install nerium[pg] --pre\n```\n\nThen add a `query_files` (and, optionally, `format_files`) directory to your project, write your queries, and configure the app as described in the next section. The command `nerium` starts a local `uvicorn` server running the app, listening on port 5042.\n\n## Configuration\n\n`DATABASE_URL` for query connections must be set in the environment (or in a local `.env` file). This is the simplest configuration option.\n\nBecause the web service uses Responder, it will also respect `PORT` if set in the environment.\n\n### Script file paths\n\nBy default, Nerium looks for query and format schema files in `query_files` and `format_files` respectively, in the current working directory from which the service is launched. `QUERY_PATH` and `FORMAT_PATH` environment variables can optionally be set in order to use files from other locations on the filesystem.\n\n### Data Sources\n\nIf you want to query multiple databases from a single Nerium installation, any individual query file can define its own `database_url` as a key in YAML front matter (see below).\n\nAlternatively, to handle multiple files with the same connection, create a subdirectory for each database under the `$QUERY_PATH`, place the related files under their respective directory, and include a separate `db.yaml` file per subdirectory, which defines the `database_url` key.\n\n_NOTE_: A `database_url` setting in front matter of a particular file will override subdirectory-level `db.yaml` setting as well as `DATABASE_URL` in the environment.\n\n## Usage\n\n## Query files\n\nAs indicated above, queries are simply text files placed in local `query_files` directory, or another arbitrary filesystem location specified by `QUERY_PATH` in the environment. The base name of the file (`stem` in Python `pathlib` parlance) will determine the `{query_name}` portion of the matching API endpoint; the file extension (or `suffix`) maps to the query type (literally the name of the `nerium.resultset` module that will handle the query).\n\nNote that Nerium loads the query files on server start; while adding additional query scripts does not require any code or config changes, the server needs to be restarted in order to use them.\n\n### Front matter\n\nQuery files can optionally include a [YAML](http://yaml.org/) front matter block. The front matter goes at the top of the file, set off by triple-dashed lines, as in this example:\n\n```yaml\n---\nAuthor: Joelle van Dyne\nDescription: Returns all active usernames in the system\n---\nselect username from user;\n\n```\n\nAt present, the Nerium service doesn't do much with the front matter. As noted above, it can be used to specify a database connection for the query. For other keys, the default response format simply passes the keys and values along in a `metadata` object. (The `compact` formatter simply ignores the metadata.) This mechanism can theoretically be used to pass relevant information about the query along to any clients of the service: for example, the data types of the columns in the results or what have you. Possibilities include whatever a reporting service and front end developer want to coordinate on. Front matter could also be used in more detailed ways in formatters yet to be devised.\n\n### Jinja templating\n\nNerium supports [Jinja](http://jinja.pocoo.org/docs/dev/templates/) templating syntax in queries. The most typical use case would be for adding optional filter clauses to a query so that the same `SELECT` statement can be reused without having to be repeated in multiple files, for example:\n\n```sql\nselect username\n , user_id\n , display_name\n from user\n{% if group %}\n where user.group = :group\n{% endif %}\n```\n\nJinja filters and other logic can be applied to inputs, as well.\n\n---\n***WARNING!***\n\nThe Jinja template is rendered in a `SandboxedEnvironment`, which should protect against [server-side template injection](https://portswigger.net/blog/server-side-template-injection) and most [SQL injection](https://en.wikipedia.org/wiki/SQL_injection) tactics. It should not be considered perfectly safe, however. Use this feature sparingly, stick with SQLAlchemy-style `:key` named parameters for bind value substitutions, and test your specific queries carefully. It should almost go without saying that database permission grants to the user Nerium connects as should be well-restricted, whether one is using Jinja syntax or not.\n\nOne known dangerous case is if your entire query file just does a Jinja variable expansion and nothing else: `{{ my_whole_query }}`. *This will allow execution of arbitrary SQL and you should **never** make a template like this available.*\n\n---\n\n## Custom format files\n\nFor serialization formats besides the built-in default and `compact`, schema definitions can be added to your `format_files` directory, using the Python [marshmallow](https://marshmallow.readthedocs.io) library. Similarly to query files, the app will look for a format module name matching the `{format}` specified in the endpoint URL. The app expects a `marshmallow.Schema` subclass named `ResultSchema`. Available attributes passed to this schema are all those in the [original `query` object](nerium/query.py#L29) with additional `result` and `params` attributes added. (See [`nerium/schema`](nerium/schema) for examples of how this is done by built-in formats.)\n\n## Query type extensions\n\nA `resultset` module is expected to have a `result` method that takes a `query` object and optional keyword argument (`kwargs`) dictionary, connects to a data source, and returns tabular results as a serializable Python structure (most typically a list of dictionaries).\n\nA Nerium `query` object is a [munchified](https://github.com/Infinidat/munch) dictionary, with elements found in [`get_query()`](nerium/query.py#L29).\n\nQuery files to be passed to this module should be named with a file extension that matches the module name (for example, `foo.sql` will be handed to the `resultset/sql.py` module).\n\n## API\n\n### URLs\n\n- `/v1/?` \n- `/v1//?`\n\n`query_name` should match the name of a given query script file, minus the file extension. URL querystring parameters are passed to the invoked data source query, matched to any keys specified in the query file. If any parameters expected by the query are missing, an error will be returned. Extra/unrecognized parameters are silently ignored (this might seem surprising, but it's standard SQLAlchemy behavior for parameter substitution).\n\n`format` path may be included as an optional formatter name, and defaults to 'default'. Other supported `formatter` options are described in Content section below.\n\nUnknown values passed to `query_extension` or `format` will silently fall back to defaults.\n\n### Method\n\n`GET`\n\n### Success Response\n\n**Code**: 200\n\n**Content**: \n\n'default': `{\"name\": \"\", \"data\": [{:, etc..., }, {etc...}, ], \"metadata\": {: , etc..., }, \"params\": {}}` \n'compact': `{\"columns\": [], \"data\": []}` \n\nOf course, it is possible that a database query might return no results. In this case, Nerium will respond with an empty JSON array `[]` regardless of specified format. This is not considered an error, and clients should be prepared to handle it appropriately.\n\n- `/v1//csv`\n\n### Method\n\n`GET`\n\n### Success Response\n\n**Code**: 200 \n\n**Content**:\n\n``\n\n### Error Responses\n\n**Code**: 400\n\n**Content**: `{\"error\": }`\n\n## Sketchy Roadmap/TODOs\n\n(in no particular order)\n\n- More detailed documentation, especially about usage\n- Parameter discovery endpoint\n- Report listing endpoint\n- ~~Dynamic filtering~~\n- ~~Improve/mature plugin architecture~~\n - ~~Separate base classes to a library~~\n - ~~Implementation subclasses in `contrib` package~~\n - ~~Refactor plugin approach to use modules with an interface standard, instead of abstract class inheritance~~\n- ~~Configurable/flexible JSON output formatters (`AffixFormatter` could do with less hard-coding)~~ [Implemented via marshmallow schemas]\n- Static output file generator (and other caching)\n- Swagger docs\n- ~~Health check/default query endpoint~~ ~~(Own git commit hash report(?))~~\n- ~~Convert app.py to [Responder](https://python-responder.org)~~\n\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/tym-xqo/nerium", "keywords": "", "license": "Apache License, Version 2.0", "maintainer": "", "maintainer_email": "", "name": "Nerium", "package_url": "https://pypi.org/project/Nerium/", "platform": "", "project_url": "https://pypi.org/project/Nerium/", "project_urls": { "Homepage": "https://github.com/tym-xqo/nerium" }, "release_url": "https://pypi.org/project/Nerium/0.5.4/", "requires_dist": [ "python-dotenv", "python-frontmatter", "pyyaml", "records", "responder", "PyMySQL ; extra == 'mysql'", "psycopg2 ; extra == 'pg'" ], "requires_python": ">=3.6.0", "summary": "The little business intelligence engine that could.", "version": "0.5.4" }, "last_serial": 4891275, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "ff242b244252888359b8910f234b7f47", "sha256": "12ce240cd939d2f48bf3096b4e26049b0b1ea2f105b49d5188920a2fbc6dab85" }, "downloads": -1, "filename": "nerium-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "ff242b244252888359b8910f234b7f47", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9830, "upload_time": "2018-05-02T18:20:55", "url": "https://files.pythonhosted.org/packages/37/36/6249704f1813625a0bebf0e54ee58776801ceadd64bbb55a193c91dfd812/nerium-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "973aa342f35fc3874afd6717431cfa12", "sha256": "11e60a247372d52ab04a655271091c8bb71c1267b38258eb92e0f9e976488756" }, "downloads": -1, "filename": "nerium-0.1.1.tar.gz", "has_sig": false, "md5_digest": "973aa342f35fc3874afd6717431cfa12", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7320, "upload_time": "2018-05-02T18:20:56", "url": "https://files.pythonhosted.org/packages/01/5a/b2eb39c72f858e14ed7beb737bc4ef00fad98b41246f8e01973a908ef4cd/nerium-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "74c4ead7025ed10fc5e9b97975b914f9", "sha256": "c9d3c338c9e8770f05453288ed9aee1cd6349b25c8898eccca229fd88b9b3607" }, "downloads": -1, "filename": "nerium-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "74c4ead7025ed10fc5e9b97975b914f9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9833, "upload_time": "2018-05-02T18:44:33", "url": "https://files.pythonhosted.org/packages/0b/7e/bc9f2ba4164f7021faabf4f5c2ef7c12f0e8d6b0fef63e6fe2f6faae638a/nerium-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e224134e30b9f3c39f818ff7cd44238f", "sha256": "7eb92da7bed4ca9907f80726c0f1035559d8a4e30aef47131e3b91db89737b66" }, "downloads": -1, "filename": "nerium-0.1.2.tar.gz", "has_sig": false, "md5_digest": "e224134e30b9f3c39f818ff7cd44238f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7325, "upload_time": "2018-05-02T18:44:34", "url": "https://files.pythonhosted.org/packages/51/65/fdbbc662c9ec72d4d1ac7f477822929b000e767434bc6c84c8a239ba250e/nerium-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "cd8a551b08f022bbf5aea597cc325268", "sha256": "8a428141e5d904b49df41e5318af9b694d1201ade943fe578464ee1c7233f737" }, "downloads": -1, "filename": "nerium-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "cd8a551b08f022bbf5aea597cc325268", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10705, "upload_time": "2018-05-11T17:29:19", "url": "https://files.pythonhosted.org/packages/a8/67/fd90c169582844605a6f3eeb30f95b0041cb8c0154dc7c534b8e571ab736/nerium-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e7355b2b6eb7898983a6c75257d00565", "sha256": "b7d6c3d66a95408578de67d488a1bfe6c773ddf16de47e5e8b43c1b0790fcb7b" }, "downloads": -1, "filename": "nerium-0.1.3.tar.gz", "has_sig": false, "md5_digest": "e7355b2b6eb7898983a6c75257d00565", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7937, "upload_time": "2018-05-11T17:29:20", "url": "https://files.pythonhosted.org/packages/d7/54/783e2bb217ef9219056cf1661534f6a536e2f72ed2ae10ab3d527b4e5b4c/nerium-0.1.3.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "fd051a3f3b1fa0acc67ec85280af423f", "sha256": "5e38e212bf25a7b2d5f3c90b739375b6735e1f2499ab325e72cf0eb5341936bd" }, "downloads": -1, "filename": "nerium-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "fd051a3f3b1fa0acc67ec85280af423f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 25750, "upload_time": "2018-11-27T17:03:29", "url": "https://files.pythonhosted.org/packages/76/91/53a7c5c4f034746527c23c0643d61fae8fb1ac8b9e7b3dee940c13b8c70c/nerium-0.3-py3-none-any.whl" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "5d6cef41cd84d70b0f659194f5050d82", "sha256": "05437b07921881421979410d174db4ebb458f1a3e1bd6068941ba0fdb3c8ed3b" }, "downloads": -1, "filename": "nerium-0.3.1-py3.7.egg", "has_sig": false, "md5_digest": "5d6cef41cd84d70b0f659194f5050d82", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 16257, "upload_time": "2019-01-02T20:25:36", "url": "https://files.pythonhosted.org/packages/31/29/aff0c9e5fe5443c4cf1e93bbe45b92f937c10e6a1dc25659674c872de243/nerium-0.3.1-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "e74af39dd88c491823f8d987699b9e13", "sha256": "8379d3ad8dd86abf934558395f3ffafbddb866a0fbb8fae79f29d70c8dd073ac" }, "downloads": -1, "filename": "nerium-0.3.1.tar.gz", "has_sig": false, "md5_digest": "e74af39dd88c491823f8d987699b9e13", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15458, "upload_time": "2018-11-27T17:11:50", "url": "https://files.pythonhosted.org/packages/cb/d2/29a9eb58ade6ddb575a387edeaa06fe6c68cf72d3ce4d9c923083cb65f3e/nerium-0.3.1.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "1b69b7c4ddc82d6ba7eb3313501e1630", "sha256": "628e3ce63a2d4fe938ea3076138d92dfc037613e5c31e3bddcf30ed3c711b8f0" }, "downloads": -1, "filename": "nerium-0.4-py3.7.egg", "has_sig": false, "md5_digest": "1b69b7c4ddc82d6ba7eb3313501e1630", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 24125, "upload_time": "2018-12-23T04:28:46", "url": "https://files.pythonhosted.org/packages/d0/db/bd19f2edbf390948d32dad88250615a97d50edee90fdf79a06978832bd84/nerium-0.4-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "5b7b7c2f7832d7528e5e122e1c8d98dd", "sha256": "1fde1f8f35ebdfc197c9664019c7574eb0e39efe3498a0cedf3d2dc75ab012a2" }, "downloads": -1, "filename": "nerium-0.4.tar.gz", "has_sig": false, "md5_digest": "5b7b7c2f7832d7528e5e122e1c8d98dd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13343, "upload_time": "2018-12-06T01:59:28", "url": "https://files.pythonhosted.org/packages/8f/4b/4c9974a8ec4076026b783f33af9a4da2fc108be8be14e6babfbb1a93ed83/nerium-0.4.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "a8cc6b4a3b5429bc1339a88bee159d51", "sha256": "dbfe4e4f553e34eb338dc04e0605905406f82a0c893e69fdb6e53941cb287b93" }, "downloads": -1, "filename": "nerium-0.4.1.tar.gz", "has_sig": false, "md5_digest": "a8cc6b4a3b5429bc1339a88bee159d51", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16019, "upload_time": "2018-12-23T04:28:49", "url": "https://files.pythonhosted.org/packages/aa/97/a84a6afd0dd7574c6c1fea5aa56f159a111dbfb3cb95f1681c98dc107307/nerium-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "aa18637bf962f40e3e62db91ce6a9258", "sha256": "34634744c6716be664d1b7e4999512e3c7eb341841f7816911709f023b8858a1" }, "downloads": -1, "filename": "nerium-0.4.2.tar.gz", "has_sig": false, "md5_digest": "aa18637bf962f40e3e62db91ce6a9258", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16027, "upload_time": "2019-01-02T20:25:39", "url": "https://files.pythonhosted.org/packages/1a/61/ee3603c4106d9bcd6a2caae83ba69cdb99cc0ade3ec3ad3c6844af49ad40/nerium-0.4.2.tar.gz" } ], "0.5.4": [ { "comment_text": "", "digests": { "md5": "90d77912b71ae8e7f30486c99eecac4a", "sha256": "be1a7124c37c0fed5eea329333fb42c83fdc2fd3dd9c95ebd96bc12f22fcb561" }, "downloads": -1, "filename": "Nerium-0.5.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "90d77912b71ae8e7f30486c99eecac4a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 16566, "upload_time": "2019-03-03T16:39:10", "url": "https://files.pythonhosted.org/packages/32/49/357e6c75d3c47a7be82f2084369f5f12d4597351a4350d44e0f8968b77b1/Nerium-0.5.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5e0261851780f09d2d87940f6d08754c", "sha256": "c85fbb5da26e37d7f884ee4226a931e6e105cf7f5e906bcda048e14c7c000628" }, "downloads": -1, "filename": "Nerium-0.5.4.tar.gz", "has_sig": false, "md5_digest": "5e0261851780f09d2d87940f6d08754c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 12327, "upload_time": "2019-03-03T16:39:12", "url": "https://files.pythonhosted.org/packages/5b/02/d11a58b82c1413a2b033b41ed5010299511ec9a43e4d452f3cbf7d75534d/Nerium-0.5.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "90d77912b71ae8e7f30486c99eecac4a", "sha256": "be1a7124c37c0fed5eea329333fb42c83fdc2fd3dd9c95ebd96bc12f22fcb561" }, "downloads": -1, "filename": "Nerium-0.5.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "90d77912b71ae8e7f30486c99eecac4a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 16566, "upload_time": "2019-03-03T16:39:10", "url": "https://files.pythonhosted.org/packages/32/49/357e6c75d3c47a7be82f2084369f5f12d4597351a4350d44e0f8968b77b1/Nerium-0.5.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5e0261851780f09d2d87940f6d08754c", "sha256": "c85fbb5da26e37d7f884ee4226a931e6e105cf7f5e906bcda048e14c7c000628" }, "downloads": -1, "filename": "Nerium-0.5.4.tar.gz", "has_sig": false, "md5_digest": "5e0261851780f09d2d87940f6d08754c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 12327, "upload_time": "2019-03-03T16:39:12", "url": "https://files.pythonhosted.org/packages/5b/02/d11a58b82c1413a2b033b41ed5010299511ec9a43e4d452f3cbf7d75534d/Nerium-0.5.4.tar.gz" } ] }