{ "info": { "author": "Glenn Amundsen", "author_email": "amundsen.glenn@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Database", "Topic :: Scientific/Engineering :: Artificial Intelligence", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "There will be many times when we need to run SQL queries via python code. Often this is hadeled by copying our sql into our python code as a string and executed it using jaydebeapi. This works well enough but makes version control a pain if we are editing sql files and then copying them into our python, especially if we are outsourcing the actual development of the queries to another team.\n\nSqlParser is a Python package that wraps around jaydebeapi that seeks to address this issue by automatically parsing our SQL queries based on a few simple annotations that get added when a query is being developed.\n\nThis is currently only tested for teradata but it should work with any database supported by jaydebeapi.\n\n### SQL Annotation\nThere are three types of sql \"Blocks\" that can be created using the following annotations:\n--:--SETUP\nThese are queries that get run first to maybe create some intermediate table. No data is returned from these\n--:--DATA: output_filename\nThese are queries that extract data, and get saved under theme given inlace of \"output_filename\"\n--:--CLEANUP\nFinally these are queries that get run last two do any cleanup that needs to be done, maybe to remove and intermediate table.\n\nYou can have more than one of each block and within each Block, you can have multiple commands and each should be terminated by a semicolon (;). Note: Data blocks should only contain one command.\n Here is a simple example using all three types of block but note you will often only need a \"DATA\" block:\n\nExample Annotated SQL\n\n```sql\n--:--SETUP\nCREATE table temporary_table as\nSelect * from table_a a\nJoin table_b b\non a.key = b.key;\n\nCREATE table temporary_table2 as\nSelect * from new_table_a a\nJoin table_b b\non a.key = b.key;\n\n--:--DATA: tracked\nSelect * from temporaty_table\nWhere package_type = \u201ctracked\u201d;\n\n--:--DATA: sd_agg\nSelect route_id, count(barcode)\nFrom temporary_table\nWhere package_type = \u201cspecial_delivery\u201d\ngroupby 1;\n\n\n--:--CLEANUP\nDROP table temporary_table;\nDROP table temporary_table2;\n```\n\n### Using the Parser\nOnce you have annotated your sql you can easily use the SqlParser to parse and execute your commands. Here is a simple example:\nSqlParser Example\n\n```python\nimport glob\nimport yaml\nfrom sqlparser import SqlParser\n\n\n#load credentials\nwith open('credentials.yaml', 'r') as file:\n creds = yaml.load(file)\n\n#create a parser and point it to where you want the sql extracts to be stored\nparser = SqlParser(output_basepath=\"/path/to/store/files/\", sep=\"|\")\n\n#set the address and credentials\nparser.set_address(\"//00.000.00.000/DBS_PORT=0000\") #replace address with ip and port of your database\nparser.set_credentials(creds['td_username'], creds['td_password'])\nparser.open_connection()\n\n#run all the queries you want executed\nqueries = glob.glob(\"path/to/annotated/files/*.sql\")\nfor query in queries:\n parser.parse_sql(path=query)\n parser.run_all()\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": "", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "sqlparser", "package_url": "https://pypi.org/project/sqlparser/", "platform": "", "project_url": "https://pypi.org/project/sqlparser/", "project_urls": null, "release_url": "https://pypi.org/project/sqlparser/0.0.9/", "requires_dist": null, "requires_python": "", "summary": "This package helps automatically parse and execute sql queries", "version": "0.0.9" }, "last_serial": 4631288, "releases": { "0.0.5": [ { "comment_text": "", "digests": { "md5": "5a3f4aa466de98c282d126cead0b903b", "sha256": "c3a89b4dfd96a7f987890e5e6a462c856d566bbbaa112883b77c87f9b471f455" }, "downloads": -1, "filename": "sqlparser-0.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "5a3f4aa466de98c282d126cead0b903b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17735, "upload_time": "2018-12-20T15:33:47", "url": "https://files.pythonhosted.org/packages/94/b4/0729ce52bacad27569c7d2917c2ddab04dd7573e34c4de5fb9bd02ca4932/sqlparser-0.0.5-py3-none-any.whl" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "cb92495c2be232170987880659869cab", "sha256": "329ffe4641f6aeec6a64eab0624cbee1bc0cc1ff186ff07ff5dd0f83c19c10e3" }, "downloads": -1, "filename": "sqlparser-0.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "cb92495c2be232170987880659869cab", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21802, "upload_time": "2018-12-20T15:39:26", "url": "https://files.pythonhosted.org/packages/db/f6/eba8b4ff2e5a4f06583a50516f67b5219f322de18fc8dc8b6da9508d4f9e/sqlparser-0.0.6-py3-none-any.whl" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "108ec02d76ac926ef360ddfa78c60718", "sha256": "4b0fe4d92b759e302a945e647bb4e509a9ca3d12b9e49626e6a4a5f2fe1882ef" }, "downloads": -1, "filename": "sqlparser-0.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "108ec02d76ac926ef360ddfa78c60718", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21812, "upload_time": "2018-12-20T15:41:50", "url": "https://files.pythonhosted.org/packages/ea/b9/3f459a622c5bbedb5afc7fe1ee39ff1374f3fc60c740e0ccfc9d0c266431/sqlparser-0.0.7-py3-none-any.whl" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "745e50b546d2b04e85d437218aaedff3", "sha256": "3906c4ca435c0aece4de0a260d245876c173fb058dc401eef7ec49e1d0e7ff52" }, "downloads": -1, "filename": "sqlparser-0.0.8-py3-none-any.whl", "has_sig": false, "md5_digest": "745e50b546d2b04e85d437218aaedff3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21816, "upload_time": "2018-12-24T10:14:25", "url": "https://files.pythonhosted.org/packages/49/bf/f489f2affcb116dfd0cc89d1ebe4436f9b71ad07088f3584be0fa0c17eb2/sqlparser-0.0.8-py3-none-any.whl" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "a374bed30fdb3e5b7bda5f09d5ba1d08", "sha256": "790e6df69bd66103a37bf27c703ad6748939496ef7cd59eb16b20ff77b150998" }, "downloads": -1, "filename": "sqlparser-0.0.9-py3-none-any.whl", "has_sig": false, "md5_digest": "a374bed30fdb3e5b7bda5f09d5ba1d08", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21812, "upload_time": "2018-12-24T12:30:36", "url": "https://files.pythonhosted.org/packages/74/d9/17967b031764371e517a6209646a1872a8c91af2fd8f3d57c68bf1783eaa/sqlparser-0.0.9-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a374bed30fdb3e5b7bda5f09d5ba1d08", "sha256": "790e6df69bd66103a37bf27c703ad6748939496ef7cd59eb16b20ff77b150998" }, "downloads": -1, "filename": "sqlparser-0.0.9-py3-none-any.whl", "has_sig": false, "md5_digest": "a374bed30fdb3e5b7bda5f09d5ba1d08", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21812, "upload_time": "2018-12-24T12:30:36", "url": "https://files.pythonhosted.org/packages/74/d9/17967b031764371e517a6209646a1872a8c91af2fd8f3d57c68bf1783eaa/sqlparser-0.0.9-py3-none-any.whl" } ] }