Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docs for creating a GoogleDriveFile by ID #368

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/file.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
File referencing made easy
=============================

*PyDrive* can create a single `GoogleDriveFile`_ if you already know
the file's ID.

Specify a file by ID
--------------------

Create a `GoogleDriveFile`_ instance with a ``dict`` specifying the
Google Drive file ID. Then call the various ``GetContent*()`` methods
(i.e., `GetContentString()`_, `GetContentFile()`_, and
`GetContentIOBuffer()`_) to download contents of that file.

.. code-block:: python

import mimetypes
from pydrive2.files import GoogleDriveFile

# Download a file as a PPTX (e.g., a Google Slides file, or even
# an actual PPTX file)
def download_pptx(id, output_file='my-slides.pptx'):
mtype = mimetypes.guess_type(output_file)[0]
gfile = GoogleDriveFile(gauth, {'id': id})
gfile.GetContentFile(filename=output_file, mimetype=mtype)

# Download a text file as a string
def download_text_file(id):
mtype = 'text/plain'
gfile = GoogleDriveFile(gauth, {'id': id})
return gfile.GetContentString(mimetype=mtype)

.. _`GoogleDriveFile`: /PyDrive2/pydrive2/#pydrive2.files.GoogleDriveFile
.. _`GetContentFile()`: /PyDrive2/pydrive2/#pydrive2.files.GetContentFile
.. _`GetContentString()`: /PyDrive2/pydrive2/#pydrive2.files.GetContentString
.. _`GetContentIOBuffer()`: /PyDrive2/pydrive2/#pydrive2.files.GetContentIOBuffer
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Table of Contents
oauth
filemanagement
filelist
file
fsspec
pydrive2
genindex