Skip to content

Switch to official dbapi #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 9, 2017
57 changes: 42 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
DB-API interface and SQLAlchemy dialect for BigQuery. Inspired by `PyHive <https://github.com/dropbox/PyHive/>`_.
SQLAlchemy dialect for BigQuery.


Usage
=====

DB-API
------
.. code-block:: python

import bigquery
cursor = bigquery.connect('project').cursor()
cursor.execute('SELECT * FROM dataset.table LIMIT 10')
print(cursor.fetchone())
print(cursor.fetchall())

SQLAlchemy
----------
.. code-block:: python

from sqlalchemy import *
Expand All @@ -25,15 +13,54 @@ SQLAlchemy
logs = Table('dataset.table', MetaData(bind=engine), autoload=True)
print(select([func.count('*')], from_obj=logs).scalar())


Project
_______
`project` in `bigquery://project` is used to instantiate BigQuery client with the specific project ID. To infer project from the environment, use `bigquery://` – without `project`

Table names
___________
To query tables from non-default projects, use the following format for the table name: `project.dataset.table`, e.g.:

.. code-block:: python

sample_table = Table('bigquery-public-data.samples.natality')

Batch size
__________

By default, `arraysize` is set to `5000`. `arraysize` is used to set the batch size for fetching results. To change it, pass `arraysize` to `create_engine()`:

.. code-block:: python

engine = create_engine('bigquery://project', arraysize=1000)


Requirements
============

Install using

- ``pip install git+https://github.com/mxmzdlv/pybigquery.git@master#egg=pybigquery``
- ``pip install pybigquery``


Testing
============

Load sample tables:

./scripts/load_test_data.sh

This will create a dataset `test_pybigquery` with tables named `sample_one_row` and `sample`

Set up an environment and run tests:
pyvenv .env
source .env/bin/activate
pip install -r dev_requirements.txt
pytest


TODO
====

- Support for Record column type
- Add a test suite
20 changes: 0 additions & 20 deletions bigquery/__init__.py

This file was deleted.

29 changes: 0 additions & 29 deletions bigquery/connection.py

This file was deleted.

143 changes: 0 additions & 143 deletions bigquery/cursor.py

This file was deleted.

54 changes: 0 additions & 54 deletions bigquery/exceptions.py

This file was deleted.

54 changes: 0 additions & 54 deletions bigquery/formatter.py

This file was deleted.

4 changes: 3 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
sqlalchemy>=1.1.9
google-cloud>=0.25.0
google-cloud-bigquery>=0.27.0

pytest==3.2.2
Loading