3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pipenv で BigQuery をいじるpythonスクリプトを動かす環境をサクッと作る

Last updated at Posted at 2019-12-11

Pipenvことはじめの記事を参考に作った時のメモ。

pipenvの環境作る

pipenvインストール


pip3 install pipenv

pipenvの環境の準備


cd path/to/project/
pipenv --python 3.7.2 # pipenv経由でpythonバージョンを指定して用意
pipenv shell # pipenvを有効にする
pipenv install google-cloud-bigquery # bigquery用のライブラリをインストール 

スクリプトを用意

例としてBigQueryのquery結果を出力するだけのスクリプト

script.py
from google.cloud import bigquery
client = bigquery.Client(project="project_name")
query = ("SELECT column1, column2 FROM `project.dataset.table`")
query_job = client.query(query, location="US")
for row in query_job:
    print(row)

実行

python script.py

※ gcpの認証はgcloud SDK経由で通しておきましょう

以上。pipenv便利。
cronでpipenv環境上ジョブを実行すると合わせてどうぞ。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?