Skip to content

Commit

Permalink
Update README and setup.py (GoogleCloudPlatform#21)
Browse files Browse the repository at this point in the history
* Updated README

* Updating setup.py

* Added init files to make them be recognized as namespace packages.

* Updated setup.py

* Updated README

* Fixed setup.py filenotfound

* Linter changes

* Added Python version to README

* Update README.md

Co-Authored-By: Christopher Wilcox <[email protected]>
  • Loading branch information
Ryan Chen and crwilcox authored Aug 16, 2019
1 parent f0272b3 commit 5b02e80
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 6 deletions.
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Cloud SQL Connector for Python Drivers
--------------------------------------------
*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 whitelist IPs or manage SSL certificates.

Currently only supports MySQL through the `pymysql` driver.

# Supported Python Versions
Currently Python versions >= 3.6 are supported.

### Authentication

This library uses the [Application Default Credentials](https://cloud.google.com/docs/authentication/production) to authenticate the
Expand All @@ -18,3 +22,56 @@ To activate credentials locally, use the following `gcloud` command:
gcloud auth application-default login
```

### How to install this connector

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

### How to use this connector

To use the connector: import the connector by including the following statement at the top of your Python file:
```Python
from google.cloud.sql.connector import connector
```

Use 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 ...
)
```


### Setup for development

Tests can be run with `nox`. Change directory into the `cloud-sql-python-connector` and just run `nox` to run the tests.

1. Create a MySQL instance on Google Cloud SQL. Make sure to note your root password when creating the MySQL instance.
2. When the MySQL instance has finished creating, go to the overview page and set the instance’s connection string to the environment variable INSTANCE_CONNECTION_NAME using the following command:
```
export INSTANCE_CONNECTION_NAME=your:connection:string
```
3. Enable SSL for your Cloud SQL instance by following [these instructions](https://cloud.google.com/sql/docs/mysql/configure-ssl-instance).
4. Create a service account with Cloud SQL Admin and Cloud SQL Client roles, then download the key and save it in a safe location. Set the path to the json file to the environment variable GOOGLE_APPLICATION_CREDENTIALS using the following command:
```
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/auth/./json
```
5. Enable the SQL Admin API.
6. Clone the [repository](https://github.com/GoogleCloudPlatform/cloud-sql-python-connector).
7. Create a virtual environment and change directory into the `cloud-sql-python-connector` folder.
8. Install the package by running the following command:
```
pip install .
```
22 changes: 22 additions & 0 deletions google/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
22 changes: 22 additions & 0 deletions google/cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
Empty file added google/cloud/sql/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions google/cloud/sql/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@
from .InstanceConnectionManager import CloudSQLConnectionError

__ALL__ = [connect, CloudSQLConnectionError]

try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
53 changes: 48 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,59 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import io
import os
from setuptools import setup, find_packages

packages = [
package for package in setuptools.find_packages() if package.startswith("google")
]
package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, "README.md")
with io.open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()

packages = [package for package in find_packages() if package.startswith("google")]

# Determine which namespaces are needed.
namespaces = ["google"]
if "google.cloud" in packages:
namespaces.append("google.cloud")

setup(name="cloud-sql-python-connector", packages=find_packages())
name = "cloud-sql-python-connector"
description = ""
version = ""
release_status = "Development Status :: 3 - Alpha"
dependencies = [
"aiohttp",
"cryptography",
"PyMySQL",
"pytest",
"Requests",
"google-api-python-client",
]

setup(
name=name,
version=version,
description=description,
long_description=readme,
author="Google LLC",
license="Apache 2.0",
url="https://github.com/GoogleCloudPlatform/cloud-sql-python-connector",
classifiers=[
release_status,
"Intended Audience :: Developers",
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
platforms="Posix; MacOS X",
packages=packages,
namespace_packages=namespaces,
install_requires=dependencies,
python_requires=">=3.6",
include_package_data=True,
zip_safe=False,
)

0 comments on commit 5b02e80

Please sign in to comment.