{ "info": { "author": "Dor Amir", "author_email": "amirdor@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "PBQ\n===\n\n[![PyPI version](https://badge.fury.io/py/pbq.svg)](https://badge.fury.io/py/pbq)\n\n[![Build Status](https://travis-ci.org/amirdor/pbq.svg?branch=master)](https://travis-ci.org/amirdor/pbq)\n\n[![Documentation Status](https://readthedocs.org/projects/pbq/badge/?version=latest)](https://pbq.readthedocs.io/en/latest/?badge=latest)\n\npython BiqQuery driver for easy access\n\n\n\nInstalling\n----------\n\nTo start using this package run:\n\n``` bash\n$ pip install pbq\n```\n\nFor development use, and local testing run:\n\n``` bash\n$ python setup.py install\n```\n\n\n\nDependency\n----------\n\n**bq Command-Line Tool**\n\nInstall bq cli -- the package is running bq cli in the background\n\n``` bash\nhttps://cloud.google.com/sdk/docs/\n```\n\nafter installation on a new terminal write:\n\n``` bash\n$ bq init\n$ gcloud auth application-default login\n```\n\nif you don't want to install bq cli you can run the package with the\nservice account key\n\nall you need to do it to define an environment variable like this:\n\n``` bash\n$ export GOOGLE_APPLICATION_CREDENTIALS=\"/home/user/Downloads/[FILE_NAME].json\"\n```\n\nUsage\n=====\n\nImport this package to your project and you are ready to go\n\n``` python\nfrom pbq import PBQ\nfrom pbq import Query\n```\n\n\n\nPBQ\n---\n\nThis class can have generic functions for big query manipulation and\nsave queries to tables.\n\n### some usages:\n\n#### Download table to CSV\n\n``` python\nfrom pbq import PBQ\nfrom pbq import Query\n\n# read sql file and format the query from file to string without parameters\nquery = Query.read_file('queries/query.sql')\n\n# init the query builder\npbq = PBQ(query)\n\n#run the query and get csv\npbq.to_csv('file.csv', save_query=True, **{'table': 'table', 'dataset': 'dataset'})\n```\n\nwhen setting save\\_query=True it means that you want to save your query\nto a table, and you need to send dictionary with the table name and\ndataset name.\n\nDownload table to pandas DataFrame\n\n``` python\nfrom pbq import PBQ\nfrom pbq import Query\n\n# read sql file and format the query from file to string without parameters\nquery = Query.read_file('queries/query.sql')\n\n# init the query builder\npbq = PBQ(query)\n\n#run the query and get dataframe\npbq.to_dataframe()\n```\n\n\n#### Save query to a table\n\n``` python\nfrom pbq import PBQ\nfrom pbq import Query\n\n# read sql file and format the query from file to string without parameters\nquery = Query('select * from table')\n\n# init the query builder\npbq = PBQ(query)\npbq.save_to_table('table_name', 'dataset_name', 'project_name', replace=True, partition='20190910')\n```\n\nWhen setting replace=True it will override the table as long as the\ntable is not partitioned, if partitioned it will overwrite the\npartition.\n\npartition format is `YYYYMMDD`\n\n\n\n#### upload DataFrame to a table\n\n``` python\nimport pandas as pd\nfrom pbq import Query, PBQ\ndf = pd.DataFrame()\nPBQ.save_dataframe_to_table(df, 'table', 'dataset', 'project_id', partition='20191013', replace=False)\n```\n\n\n\nQuery\n-----\n\nThis class will format your query, check validation and return the price\nof the query\n\n### some usages:\n\n#### generate the query object with a simple query\n\n``` python\nfrom pbq import Query\nquery = Query(\"select * from table\")\n```\n\n#### get query price\n\n``` python\nfrom pbq import Query\nquery = Query(\"select * from table\")\nprint(\"the query price:\", query.price)\n# the query price: 0.312\n```\n\n#### validate query\n\n``` python\nfrom pbq import Query\nquery = Query(\"select * from table\")\nif not query.validate():\n raise RuntimeError(\"table not valid\")\n```\n\n#### query with parameters\n\n``` python\nfrom pbq import Query\nquery = Query(\"select * from table where user_id={user_id}\", parameters={'user_id': 123})\nprint(query.query)\n# select * from table where user_id=123\n```\n\n#### read the query from file with parameters\n\n``` python\nfrom pbq import Query\nquery = Query.read_file('file_path.sql', parameters={'user_id':123})\nprint(query.query)\n# select * from table where user_id=123\n```\n\n\n- Free software: MIT license\n- Documentation: .\n\n

History\n=======\n\n0.1.0 (2019-10-03)\n------------------\n\n* First release on PyPI.\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/amirdor/pbq", "keywords": "pbq", "license": "MIT license", "maintainer": "", "maintainer_email": "", "name": "pbq", "package_url": "https://pypi.org/project/pbq/", "platform": "", "project_url": "https://pypi.org/project/pbq/", "project_urls": { "Homepage": "https://github.com/amirdor/pbq" }, "release_url": "https://pypi.org/project/pbq/0.1.1/", "requires_dist": [ "google-api-core (==1.14.*)", "google-cloud-bigquery-storage (==0.7.*)", "google-cloud-bigquery (==1.20.*)", "google-cloud-core (==1.0.*)", "pandas (==0.25.*)", "pyarrow (==0.14.*)", "fastparquet (==0.3.*)", "requests (==2.22.*)" ], "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "summary": "python bigquery driver for easy access", "version": "0.1.1" }, "last_serial": 5989216, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "1aff2e296563d95526a146f79b08db10", "sha256": "b3cb1e58f924b43770b6b4f347d795f0ba339eed40c81b0ac5225c4dd9e5ac05" }, "downloads": -1, "filename": "pbq-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1aff2e296563d95526a146f79b08db10", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 8363, "upload_time": "2019-10-17T11:22:16", "url": "https://files.pythonhosted.org/packages/ac/d7/f91ef5cf23735e5f63f065eb8cdd914cd471c121c8c09f315dc7541b611e/pbq-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e1e546ff758c1ce891402972d5a2c2eb", "sha256": "46be870699795ba976b57b3e9b15f0dea669b6da11145949f9b74da6dab2a100" }, "downloads": -1, "filename": "pbq-0.1.1.tar.gz", "has_sig": false, "md5_digest": "e1e546ff758c1ce891402972d5a2c2eb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 15992, "upload_time": "2019-10-17T11:22:18", "url": "https://files.pythonhosted.org/packages/6d/ba/1de00d1beda2384640ce482a17aca96e00ef001aa4d736abcd4a0ef1d6db/pbq-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1aff2e296563d95526a146f79b08db10", "sha256": "b3cb1e58f924b43770b6b4f347d795f0ba339eed40c81b0ac5225c4dd9e5ac05" }, "downloads": -1, "filename": "pbq-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1aff2e296563d95526a146f79b08db10", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 8363, "upload_time": "2019-10-17T11:22:16", "url": "https://files.pythonhosted.org/packages/ac/d7/f91ef5cf23735e5f63f065eb8cdd914cd471c121c8c09f315dc7541b611e/pbq-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e1e546ff758c1ce891402972d5a2c2eb", "sha256": "46be870699795ba976b57b3e9b15f0dea669b6da11145949f9b74da6dab2a100" }, "downloads": -1, "filename": "pbq-0.1.1.tar.gz", "has_sig": false, "md5_digest": "e1e546ff758c1ce891402972d5a2c2eb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "size": 15992, "upload_time": "2019-10-17T11:22:18", "url": "https://files.pythonhosted.org/packages/6d/ba/1de00d1beda2384640ce482a17aca96e00ef001aa4d736abcd4a0ef1d6db/pbq-0.1.1.tar.gz" } ] }