Skip to content
This repository was archived by the owner on Jul 22, 2021. It is now read-only.

Commit 8cb4aad

Browse files
committed
Initial Import
0 parents  commit 8cb4aad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+17649
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.pyc
2+
*~
3+
pydrive/test/configs/*
4+
pydrive/test/credentials/*
5+
6+
*.egg-info
7+
dist

AUTHORS

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Please contribute to this project to make Google drive development experience better in Python.
2+
3+
* JunYoung Gwak

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v1.0.0, Aug 16, 2013 -- Initial release.

LICENSE

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
Copyright 2013 Google Inc. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
6+
Unless required by applicable law or agreed to in writing, software
7+
distributed under the License is distributed on an "AS IS" BASIS,
8+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and
10+
limitations under the License.
11+
12+
Apache License
13+
Version 2.0, January 2004
14+
http://www.apache.org/licenses/
15+
16+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
17+
18+
1. Definitions.
19+
20+
"License" shall mean the terms and conditions for use, reproduction,
21+
and distribution as defined by Sections 1 through 9 of this document.
22+
23+
"Licensor" shall mean the copyright owner or entity authorized by
24+
the copyright owner that is granting the License.
25+
26+
"Legal Entity" shall mean the union of the acting entity and all
27+
other entities that control, are controlled by, or are under common
28+
control with that entity. For the purposes of this definition,
29+
"control" means (i) the power, direct or indirect, to cause the
30+
direction or management of such entity, whether by contract or
31+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
32+
outstanding shares, or (iii) beneficial ownership of such entity.
33+
34+
"You" (or "Your") shall mean an individual or Legal Entity
35+
exercising permissions granted by this License.
36+
37+
"Source" form shall mean the preferred form for making modifications,
38+
including but not limited to software source code, documentation
39+
source, and configuration files.
40+
41+
"Object" form shall mean any form resulting from mechanical
42+
transformation or translation of a Source form, including but
43+
not limited to compiled object code, generated documentation,
44+
and conversions to other media types.
45+
46+
"Work" shall mean the work of authorship, whether in Source or
47+
Object form, made available under the License, as indicated by a
48+
copyright notice that is included in or attached to the work
49+
(an example is provided in the Appendix below).
50+
51+
"Derivative Works" shall mean any work, whether in Source or Object
52+
form, that is based on (or derived from) the Work and for which the
53+
editorial revisions, annotations, elaborations, or other modifications
54+
represent, as a whole, an original work of authorship. For the purposes
55+
of this License, Derivative Works shall not include works that remain
56+
separable from, or merely link (or bind by name) to the interfaces of,
57+
the Work and Derivative Works thereof.
58+
59+
"Contribution" shall mean any work of authorship, including
60+
the original version of the Work and any modifications or additions
61+
to that Work or Derivative Works thereof, that is intentionally
62+
submitted to Licensor for inclusion in the Work by the copyright owner
63+
or by an individual or Legal Entity authorized to submit on behalf of
64+
the copyright owner. For the purposes of this definition, "submitted"
65+
means any form of electronic, verbal, or written communication sent
66+
to the Licensor or its representatives, including but not limited to
67+
communication on electronic mailing lists, source code control systems,
68+
and issue tracking systems that are managed by, or on behalf of, the
69+
Licensor for the purpose of discussing and improving the Work, but
70+
excluding communication that is conspicuously marked or otherwise
71+
designated in writing by the copyright owner as "Not a Contribution."
72+
73+
"Contributor" shall mean Licensor and any individual or Legal Entity
74+
on behalf of whom a Contribution has been received by Licensor and
75+
subsequently incorporated within the Work.
76+
77+
2. Grant of Copyright License. Subject to the terms and conditions of
78+
this License, each Contributor hereby grants to You a perpetual,
79+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
80+
copyright license to reproduce, prepare Derivative Works of,
81+
publicly display, publicly perform, sublicense, and distribute the
82+
Work and such Derivative Works in Source or Object form.
83+
84+
3. Grant of Patent License. Subject to the terms and conditions of
85+
this License, each Contributor hereby grants to You a perpetual,
86+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
87+
(except as stated in this section) patent license to make, have made,
88+
use, offer to sell, sell, import, and otherwise transfer the Work,
89+
where such license applies only to those patent claims licensable
90+
by such Contributor that are necessarily infringed by their
91+
Contribution(s) alone or by combination of their Contribution(s)
92+
with the Work to which such Contribution(s) was submitted. If You
93+
institute patent litigation against any entity (including a
94+
cross-claim or counterclaim in a lawsuit) alleging that the Work
95+
or a Contribution incorporated within the Work constitutes direct
96+
or contributory patent infringement, then any patent licenses
97+
granted to You under this License for that Work shall terminate
98+
as of the date such litigation is filed.
99+
100+
4. Redistribution. You may reproduce and distribute copies of the
101+
Work or Derivative Works thereof in any medium, with or without
102+
modifications, and in Source or Object form, provided that You
103+
meet the following conditions:
104+
105+
(a) You must give any other recipients of the Work or
106+
Derivative Works a copy of this License; and
107+
108+
(b) You must cause any modified files to carry prominent notices
109+
stating that You changed the files; and
110+
111+
(c) You must retain, in the Source form of any Derivative Works
112+
that You distribute, all copyright, patent, trademark, and
113+
attribution notices from the Source form of the Work,
114+
excluding those notices that do not pertain to any part of
115+
the Derivative Works; and
116+
117+
(d) If the Work includes a "NOTICE" text file as part of its
118+
distribution, then any Derivative Works that You distribute must
119+
include a readable copy of the attribution notices contained
120+
within such NOTICE file, excluding those notices that do not
121+
pertain to any part of the Derivative Works, in at least one
122+
of the following places: within a NOTICE text file distributed
123+
as part of the Derivative Works; within the Source form or
124+
documentation, if provided along with the Derivative Works; or,
125+
within a display generated by the Derivative Works, if and
126+
wherever such third-party notices normally appear. The contents
127+
of the NOTICE file are for informational purposes only and
128+
do not modify the License. You may add Your own attribution
129+
notices within Derivative Works that You distribute, alongside
130+
or as an addendum to the NOTICE text from the Work, provided
131+
that such additional attribution notices cannot be construed
132+
as modifying the License.
133+
134+
You may add Your own copyright statement to Your modifications and
135+
may provide additional or different license terms and conditions
136+
for use, reproduction, or distribution of Your modifications, or
137+
for any such Derivative Works as a whole, provided Your use,
138+
reproduction, and distribution of the Work otherwise complies with
139+
the conditions stated in this License.
140+
141+
5. Submission of Contributions. Unless You explicitly state otherwise,
142+
any Contribution intentionally submitted for inclusion in the Work
143+
by You to the Licensor shall be under the terms and conditions of
144+
this License, without any additional terms or conditions.
145+
Notwithstanding the above, nothing herein shall supersede or modify
146+
the terms of any separate license agreement you may have executed
147+
with Licensor regarding such Contributions.
148+
149+
6. Trademarks. This License does not grant permission to use the trade
150+
names, trademarks, service marks, or product names of the Licensor,
151+
except as required for reasonable and customary use in describing the
152+
origin of the Work and reproducing the content of the NOTICE file.
153+
154+
7. Disclaimer of Warranty. Unless required by applicable law or
155+
agreed to in writing, Licensor provides the Work (and each
156+
Contributor provides its Contributions) on an "AS IS" BASIS,
157+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
158+
implied, including, without limitation, any warranties or conditions
159+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
160+
PARTICULAR PURPOSE. You are solely responsible for determining the
161+
appropriateness of using or redistributing the Work and assume any
162+
risks associated with Your exercise of permissions under this License.
163+
164+
8. Limitation of Liability. In no event and under no legal theory,
165+
whether in tort (including negligence), contract, or otherwise,
166+
unless required by applicable law (such as deliberate and grossly
167+
negligent acts) or agreed to in writing, shall any Contributor be
168+
liable to You for damages, including any direct, indirect, special,
169+
incidental, or consequential damages of any character arising as a
170+
result of this License or out of the use or inability to use the
171+
Work (including but not limited to damages for loss of goodwill,
172+
work stoppage, computer failure or malfunction, or any and all
173+
other commercial damages or losses), even if such Contributor
174+
has been advised of the possibility of such damages.
175+
176+
9. Accepting Warranty or Additional Liability. While redistributing
177+
the Work or Derivative Works thereof, You may choose to offer,
178+
and charge a fee for, acceptance of support, warranty, indemnity,
179+
or other liability obligations and/or rights consistent with this
180+
License. However, in accepting such obligations, You may act only
181+
on Your own behalf and on Your sole responsibility, not on behalf
182+
of any other Contributor, and only if You agree to indemnify,
183+
defend, and hold each Contributor harmless for any liability
184+
incurred by, or claims asserted against, such Contributor by reason
185+
of your accepting any such warranty or additional liability.

MANIFEST.in

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include AUTHORS
2+
include CHANGES
3+
include LICENSE
4+
include MANIFEST.in
5+
include README.rst
6+
recursive-include docs *
7+
recursive-include pydrive/test *
8+
recursive-exclude * *.py[co]

README.rst

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
PyDrive
2+
-------
3+
4+
*PyDrive* is a wrapper library of
5+
`google-api-python-client <https://code.google.com/p/google-api-python-client/>`_
6+
that simplifies many common Google Drive API tasks.
7+
8+
Project Info
9+
------------
10+
11+
- Homepage: `https://pypi.python.org/pypi/PyDrive <https://pypi.python.org/pypi/PyDrive>`_
12+
- Documentation: `http://pythonhosted.org/PyDrive <http://pythonhosted.org/PyDrive>`_
13+
- Github: `https://github.com/googledrive/PyDrive <https://github.com/googledrive/PyDrive>`_
14+
15+
Features of PyDrive
16+
-------------------
17+
18+
- Simplifies OAuth2.0 into just few lines with flexible settings.
19+
- Wraps `Google Drive API <https://developers.google.com/drive/>`_ into
20+
classes of each resource to make your program more object-oriented.
21+
- Helps common operations else than API calls, such as content fetching
22+
and pagination control.
23+
24+
How to install
25+
--------------
26+
27+
You can install PyDrive with regular ``pip`` command.
28+
29+
::
30+
31+
$ pip install PyDrive
32+
33+
OAuth made easy
34+
---------------
35+
36+
Download *client\_secrets.json* from Google API Console and OAuth2.0 is
37+
done in two lines. You can customize behavior of OAuth2 in one settings
38+
file *settings.yaml*.
39+
40+
.. code:: python
41+
42+
43+
from pydrive.auth import GoogleAuth
44+
from pydrive.drive import GoogleDrive
45+
46+
gauth = GoogleAuth()
47+
gauth.LocalWebserverAuth()
48+
49+
drive = GoogleDrive(gauth)
50+
51+
File management made easy
52+
-------------------------
53+
54+
Upload/update the file with one method. PyDrive will do it in the most
55+
efficient way.
56+
57+
.. code:: python
58+
59+
file1 = drive.CreateFile({'title': 'Hello.txt'})
60+
file1.SetContentString('Hello')
61+
file1.Upload() # Files.insert()
62+
63+
file1['title'] = 'HelloWorld.txt' # Change title of the file
64+
file1.Upload() # Files.patch()
65+
66+
content = file1.GetContentString() # 'Hello'
67+
file1.SetContentString(content+' World!') # 'Hello World!'
68+
file1.Upload() # Files.update()
69+
70+
file2 = drive.CreateFile()
71+
file2.SetContentFile('hello.png')
72+
file2.Upload()
73+
print 'Created file %s with mimeType %s' % (file2['title'], file2['mimeType'])
74+
# Created file hello.png with mimeType image/png
75+
76+
file3 = drive.CreateFile({'id': file2['id']})
77+
print 'Downloading file %s from Google Drive' % file3['title'] # 'hello.png'
78+
file3.GetContentFile('world.png') # Save Drive file as a local file
79+
80+
File listing pagination made easy
81+
---------------------------------
82+
83+
*PyDrive* handles file listing pagination for you.
84+
85+
.. code:: python
86+
87+
# Auto-iterate through all files that matches this query
88+
file_list = drive.ListFile({'q': "'root' in parents"}).GetList()
89+
for file1 in file_list:
90+
print 'title: %s, id: %s' % (file1['title'], file1['id'])
91+
92+
# Paginate file lists by specifying number of max results
93+
for file_list in drive.ListFile({'maxResults': 10}):
94+
print 'Received %s files from Files.list()' % len(file_list) # <= 10
95+
for file1 in file_list:
96+
print 'title: %s, id: %s' % (file1['title'], file1['id'])

docs/_sources/filelist.txt

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
File listing made easy
2+
=============================
3+
4+
*PyDrive* handles paginations and parses response as list of `GoogleDriveFile`_.
5+
6+
Get all files which matches the query
7+
-------------------------------------
8+
9+
Create `GoogleDriveFileList`_ instance with `parameters of Files.list()`_ as ``dict``. Call `GetList()`_ and you will get all files that matches your query as a list of `GoogleDriveFile`_.
10+
11+
::
12+
13+
from pydrive.drive import GoogleDrive
14+
15+
drive = GoogleDrive(gauth) # Create GoogleDrive instance with authenticated GoogleAuth instance
16+
17+
# Auto-iterate through all files in the root folder.
18+
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
19+
for file1 in file_list:
20+
print 'title: %s, id: %s' % (file1['title'], file1['id'])
21+
22+
You can update metadata or content of these `GoogleDriveFile`_ instances if you need it.
23+
24+
Paginate and iterate through files
25+
----------------------------------
26+
27+
*PyDrive* provides Pythonic way of paginating and iterating through list of files. All you have to do is to limit number of results with ``maxResults`` parameter and build ``for`` loop retrieving file list from API each iteration.
28+
29+
Sample code continues from above:
30+
31+
::
32+
33+
# Paginate file lists by specifying number of max results
34+
for file_list in drive.ListFile({'q': 'trashed=true', 'maxResults': 10}):
35+
print 'Received %s files from Files.list()' % len(file_list) # <= 10
36+
for file1 in file_list:
37+
print 'title: %s, id: %s' % (file1['title'], file1['id'])
38+
39+
40+
.. _`GoogleDriveFile`: ./pydrive.html#pydrive.files.GoogleDriveFile
41+
.. _`GoogleDriveFileList`: ./pydrive.html#pydrive.files.GoogleDriveFileList
42+
.. _`parameters of Files.list()`: https://developers.google.com/drive/v2/reference/files/list#request
43+
.. _`GetList()`: ./pydrive.html#pydrive.apiattr.ApiResourceList.GetList

0 commit comments

Comments
 (0)