| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Warning: This project is experimental, and is not an officially supported Google product.
The Cloud SQL Python Connector library is a library for MySQL/Postgres Python drivers that allows users with sufficient permissions to connect to a Cloud SQL database without having to manually allowlist IPs or manage SSL certificates.
Currently only supports MySQL through the pymysql driver.
Currently Python versions >= 3.6 are supported.
This library uses the Application Default Credentials to authenticate the connection to the Cloud SQL server. For more details, see the previously mentioned link.
To activate credentials locally, use the following gcloud command:
gcloud auth application-default login
Clone this repo, cd into the cloud-sql-python-connector directory then run the following command to install the package:
pip install .
Conversely, install straight from Github using pip:
pip install git+https://github.com/GoogleCloudPlatform/cloud-sql-python-connector
To use the connector: import the connector by including the following statement at the top of your Python file:
from google.cloud.sql.connector import connectorUse the connector to create a connection object by calling the connect method. Input your connection string as the first positional argument and “mysql-connector” for the second positional argument. Insert the rest of your connection keyword arguments like user, password and database.
connector.connect(
"your:connection:string:",
"pymysql",
user="root",
password="shhh",
db="your-db-name"
... insert other kwargs ...
)
Tests can be run with nox. Change directory into the cloud-sql-python-connector and just run nox to run the tests.
export INSTANCE_CONNECTION_NAME=your:connection:string
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/auth/./json
pip install .
| Back | FazBrowse Home | New Git URL |