Skip to main content

Simple but robust tool for interacting with the Google Drive and Sheets apis via python.

Project description

Autodrive

Autodrive is designed to make it as easy as possible to interact with the Google Drive and Sheets APIs via Python. It is especially designed to provide as much assistance as possible when writing code through hints and autocompletion, as well as via thorough type checking and hinting. These features are currently optimized for VSCode, which you can download here if you wish. They should also work in other Python IDEs.


Documentation: https://autodrive-py.readthedocs.io/en/latest/


Requirements


Python 3.8+

Installation


Google API Credentials

Follow the steps outlined in the Prerequisites section here. Download and save the credentials.json file to the working directory you want to use Autodrive in.

First Connection

To test that your credentials provide the expected connection to your Google Drive account, simply instantiate an Autodrive Drive instance:

from autodrive import Drive

drive = Drive()

If your credentials file was saved as credentials.json, your browser should automatically open and prompt you to authorize the GCP project you created to access your Google Drive. Click the various Allow prompts it will show you to complete your first connection. After you see the browser switch to a page indicating you can close the process, you should see a gdrive_token.json file added to the working directory you saved your credentials.json file in. Next time you use an Autodrive element that needs to connect to your Drive, this token will be used and you will not be prompted to authorize access again until it expires.

Quickstart


The Drive class provides methods for finding and creating objects in your Google Drive, such as Folders or Sheets.

gsheet = drive.create_gsheet("my-autodrive-gsheet")

Finding IDs

If you use Drive to search for your Sheets and Folders, you don't need to supply the GSheet or Folder IDs yourself, but if you know exactly what Sheet you want, then you can directly instantiate a GSheet or folder by pulling the necessary info from the object's url.

For example, if your Sheet's url looks like this:

docs.google.com/spreadsheets/d/19k5cT9Klw1CA8Sum-olP7C0JUo6_kMiOAKDEeHPiSr8/edit#gid=0

Simply copy/paste the id between /d/ and /edit# as the gsheet_id:

from autodrive import GSheet

gsheet = GSheet(gsheet_id="19k5cT9Klw1CA8Sum-olP7C0JUo6_kMiOAKDEeHPiSr8")

Tabs: Because Google calls spreadsheets "Sheets", and their api also refers to the individual sub-sheets in a spreadsheet as "Sheets", Autodrive instead refers to them as "Tabs" for clarity.

For a tab, you can get the tab_id from:

docs.google.com/spreadsheets/d/19k5cT9Klw1CA8Sum-olP7C0JUo6_kMiOAKDEeHPiSr8/edit#gid=234276686

from autodrive import Tab

tab = Tab(
    gsheet_id="19k5cT9Klw1CA8Sum-olP7C0JUo6_kMiOAKDEeHPiSr8",
    tab_title="Sheet2",
    tab_idx=0,
    tab_id=234276686
)

For a folder:

drive.google.com/drive/u/1/folders/1wLx-KMG2jO498xa5ZumB-SEpL-TwczZI

from autodrive import Folder

folder = Folder(folder_id="1wLx-KMG2jO498xa5ZumB-SEpL-TwczZI", name="Test Folder")

Reading and Writing

You can easily download and write data from a Google Sheet using the GSheet, Tab, or Range views.

# Fetches all the data in all cells of the tab:
tab.get_data()

# Writes 8 cells (2 rows of 4 columns, starting in cell A1) to the tab:
tab.write_values(
    [
        [1, 2, 3, 4],
        [5, 6, 7, 8],
    ]
)

GSheet and Range have very similar methods, and all of them allow you to read and write data to only a specific range in the Google Sheet. See the Documentation for more.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autodrive-0.6.3.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

autodrive-0.6.3-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

Details for the file autodrive-0.6.3.tar.gz.

File metadata

  • Download URL: autodrive-0.6.3.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.10 CPython/3.8.12 Linux/5.8.0-1042-azure

File hashes

Hashes for autodrive-0.6.3.tar.gz
Algorithm Hash digest
SHA256 26b0888ed30169c7905e6f482d0ea036ea9e84fae642c859bd4d2bd9bcad3da0
MD5 953f12733f17fd9166b98923325de76e
BLAKE2b-256 b01bd615706e0a5f565b9fa2bc5cece08f1d3eb8a3ef060237a680f580275007

See more details on using hashes here.

File details

Details for the file autodrive-0.6.3-py3-none-any.whl.

File metadata

  • Download URL: autodrive-0.6.3-py3-none-any.whl
  • Upload date:
  • Size: 54.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.10 CPython/3.8.12 Linux/5.8.0-1042-azure

File hashes

Hashes for autodrive-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f530e196f9643f149f1fc89f612d9b59322f87bf4c0a5ed173e37c1a5fb8903d
MD5 d0d97f46b856a2ac66ed4a3b550f3b80
BLAKE2b-256 167775d4f0e54c6b4f337513fe56eeabf8d034417de0b95fd25a76d30d9b91ac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page