Snowflake Python用コネクタの接続方法
<作業手順>
- インストールする予定のPython用Snowflakeコネクタのバージョンを確認
- 使用しているPythonのバージョンとPython用Snowflakeコネクタのバージョンを確認し、コネクタの依存ライブラリをインストール(詳細はドキュメント参照(修正箇所は数字の箇所))
pip install -r https://raw.githubusercontent.com/snowflakedb/snowflake-connector-python/v2.7.6/tested_requirements/requirements_36.reqs
- コネクタをインストールするには、次のコマンドを実行します
pip install snowflake-connector-python==2.7.6
- 識別のためのおまじないと実行
#!/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.接続出来たら完了
参考ドキュメント
・チュートリアル
- document
https://quickstarts.snowflake.com/guide/getting_started_with_snowpark_python/index.html?index=..%2F..index&_ga=2.224288541.703868965.1658195148-1647345815.1641543128#0 - 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 - google colabとの接続
https://qiita.com/foursue/items/51920be756f1a0ab0bb7
・pythonコネクタ
-
SQLAlchemyツールキット
https://docs.snowflake.com/ja/user-guide/sqlalchemy.html -
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の使い分け