0
0

More than 1 year has passed since last update.

SnowflakeのPythonコネクタを使用する

Last updated at Posted at 2022-07-20

Snowflake Python用コネクタの接続方法

<作業手順>

  1. インストールする予定のPython用Snowflakeコネクタのバージョンを確認
  2. 使用しているPythonのバージョンとPython用Snowflakeコネクタのバージョンを確認し、コネクタの依存ライブラリをインストール(詳細はドキュメント参照(修正箇所は数字の箇所))
pip install -r https://raw.githubusercontent.com/snowflakedb/snowflake-connector-python/v2.7.6/tested_requirements/requirements_36.reqs
  1. コネクタをインストールするには、次のコマンドを実行します
pip install snowflake-connector-python==2.7.6
  1. 識別のためのおまじないと実行
#!/usr/bin/env python
import snowflake.connector

# Gets the version
ctx = snowflake.connector.connect(
    user='<user_name>',
    password='<password>',
    account='<account_identifier>'
    )
cs = ctx.cursor()
try:
    cs.execute("SELECT current_version()") --クエリの内容
    one_row = cs.fetchone()
    print(one_row[0])
finally:
    cs.close()
ctx.close()

5.接続出来たら完了

参考ドキュメント

・チュートリアル

  1. document
    https://quickstarts.snowflake.com/guide/getting_started_with_snowpark_python/index.html?index=..%2F..index&_ga=2.224288541.703868965.1658195148-1647345815.1641543128#0
  2. demo video
    https://resources.snowflake.com/webinars-thought-leadership/live-demo-building-the-future-of-data-science-with-snowpark-for-python-2?_ga=2.229007002.703868965.1658195148-1647345815.1641543128
  3. google colabとの接続
    https://qiita.com/foursue/items/51920be756f1a0ab0bb7

・pythonコネクタ

  1. SQLAlchemyツールキット
    https://docs.snowflake.com/ja/user-guide/sqlalchemy.html

  2. Python用Snowflakeコネクタ
    https://docs.snowflake.com/ja/user-guide/python-connector.html

※SQLAlchemyとORM について
https://docs.pyq.jp/column/sqlalchemy_orm.html

SQLAlchemy
データベースにはMySQLやPostgreSQLなどいくつかの種類があり、コマンドなどに違いがあります。
※ORMは自動で使用するデータベースに合わせたSQLを生成して実行してくれます。
→ORMはSQLを多用する複雑なアプリケーションを実装するときに力を発揮します

※課題
PythonコネクタとSQLAlchemyの使い分け

0
0
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
0
0