google-drive-export 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google_drive_export-0.1.0/LICENSE +21 -0
- google_drive_export-0.1.0/PKG-INFO +156 -0
- google_drive_export-0.1.0/README.md +129 -0
- google_drive_export-0.1.0/google_drive_export.egg-info/PKG-INFO +156 -0
- google_drive_export-0.1.0/google_drive_export.egg-info/SOURCES.txt +10 -0
- google_drive_export-0.1.0/google_drive_export.egg-info/dependency_links.txt +1 -0
- google_drive_export-0.1.0/google_drive_export.egg-info/entry_points.txt +2 -0
- google_drive_export-0.1.0/google_drive_export.egg-info/requires.txt +3 -0
- google_drive_export-0.1.0/google_drive_export.egg-info/top_level.txt +1 -0
- google_drive_export-0.1.0/google_drive_export.py +205 -0
- google_drive_export-0.1.0/pyproject.toml +38 -0
- google_drive_export-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Corey Goldberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: google-drive-export
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Export your Google Drive data
|
|
5
|
+
Author: Corey Goldberg
|
|
6
|
+
Maintainer: Corey Goldberg
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: homepage, https://github.com/cgoldberg/google-drive-export
|
|
9
|
+
Project-URL: source, https://github.com/cgoldberg/google-drive-export
|
|
10
|
+
Project-URL: download, https://pypi.org/project/google-drive-export
|
|
11
|
+
Keywords: google,drive,google-drive,backup,export,takeout
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: google-api-python-client==2.168.0
|
|
24
|
+
Requires-Dist: google-auth-httplib2==0.2.0
|
|
25
|
+
Requires-Dist: google-auth-oauthlib==1.2.2
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# google-drive-export
|
|
29
|
+
|
|
30
|
+
### Export your Google Drive data
|
|
31
|
+
|
|
32
|
+
- Copyright (c) 2025 [Corey Goldberg][github-home]
|
|
33
|
+
- License: [MIT][mit-license]
|
|
34
|
+
- Development: [GitHub][github-repo]
|
|
35
|
+
- Download/Install: [PyPI][pypi]
|
|
36
|
+
|
|
37
|
+
[github-home]: https://github.com/cgoldberg
|
|
38
|
+
[mit-license]: https://raw.githubusercontent.com/cgoldberg/google-drive-export/refs/heads/master/LICENSE
|
|
39
|
+
[github-repo]: https://github.com/cgoldberg/google-drive-export
|
|
40
|
+
[pypi]: https://pypi.org/project/google-drive-export
|
|
41
|
+
|
|
42
|
+
----
|
|
43
|
+
|
|
44
|
+
## About:
|
|
45
|
+
|
|
46
|
+
This is a command line tool for exporting your personal Google Drive files using the Google Drive API v3.
|
|
47
|
+
|
|
48
|
+
It will export all files that are owned by your account (not shared with you from other users), and
|
|
49
|
+
will not save native Google App files (Docs/Sheets/Slides/Forms/etc). Files are saved in their appropriate
|
|
50
|
+
directory structure inside a directory named `exported_files`.
|
|
51
|
+
|
|
52
|
+
For more information:
|
|
53
|
+
- [API Overview][api-overview]
|
|
54
|
+
- [REST API Reference][api-reference]
|
|
55
|
+
- [API Guides][api-guides]
|
|
56
|
+
|
|
57
|
+
[api-overview]: https://developers.google.com/workspace/drive/api
|
|
58
|
+
[api-reference]: https://developers.google.com/workspace/drive/api/reference/rest/v3
|
|
59
|
+
[api-guides]: https://developers.google.com/workspace/drive/api/guides/about-files
|
|
60
|
+
|
|
61
|
+
----
|
|
62
|
+
|
|
63
|
+
## Requirements:
|
|
64
|
+
|
|
65
|
+
- Python 3.9+
|
|
66
|
+
- Packages:
|
|
67
|
+
- google-api-python-client
|
|
68
|
+
- google-auth-httplib2
|
|
69
|
+
- google-auth-oauthlib
|
|
70
|
+
|
|
71
|
+
----
|
|
72
|
+
|
|
73
|
+
## Usage:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
usage: google_drive_export [-h] [--dir DIR]
|
|
77
|
+
|
|
78
|
+
options:
|
|
79
|
+
-h, --help show this help message and exit
|
|
80
|
+
--dir DIR output directory
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
----
|
|
84
|
+
|
|
85
|
+
## Installation:
|
|
86
|
+
|
|
87
|
+
### Create a virtual environment and install with pip
|
|
88
|
+
|
|
89
|
+
- On Linux/Mac:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
python3 -m venv venv
|
|
93
|
+
source venv/bin/activate
|
|
94
|
+
pip install google-drive-export
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- On Windows:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
py -m venv venv
|
|
101
|
+
venv\Scripts\activate
|
|
102
|
+
pip install google-drive-export
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
For more information on virtual env and pip, see:
|
|
106
|
+
- https://packaging.python.org/en/latest/tutorials/installing-packages
|
|
107
|
+
|
|
108
|
+
### Install globally with pipx
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
pipx install google-drive-export
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
For more information on pipx, see:
|
|
115
|
+
- https://github.com/pypa/pipx
|
|
116
|
+
|
|
117
|
+
----
|
|
118
|
+
|
|
119
|
+
## Authorization for use with Google Drive:
|
|
120
|
+
|
|
121
|
+
After installing, you must follow these steps:
|
|
122
|
+
|
|
123
|
+
### 1. Enable the Google Drive API
|
|
124
|
+
|
|
125
|
+
- Go to the Google Cloud console (Enable access to API)
|
|
126
|
+
- https://console.cloud.google.com/flows/enableapi?apiid=drive.googleapis.com
|
|
127
|
+
- Create a Project
|
|
128
|
+
- Enable the API
|
|
129
|
+
|
|
130
|
+
### 2. Configure the OAuth Consent screen
|
|
131
|
+
|
|
132
|
+
- Go to the Google Cloud console (Branding)
|
|
133
|
+
- https://console.cloud.google.com/auth/branding
|
|
134
|
+
- Configure your Project
|
|
135
|
+
- Go to the Google Cloud console (Audience)
|
|
136
|
+
- https://console.cloud.google.com/auth/audience
|
|
137
|
+
- Add yourself as a Test user
|
|
138
|
+
|
|
139
|
+
### 3. Authorize credentials for a desktop application
|
|
140
|
+
|
|
141
|
+
- Go to the Google Cloud console (Clients)
|
|
142
|
+
- https://console.cloud.google.com/auth/clients
|
|
143
|
+
- Create a Client (Application type > Desktop app)
|
|
144
|
+
- Downloaded JSON file, rename it to credentials.json, and move it to your working directory
|
|
145
|
+
|
|
146
|
+
### 4. Run the program
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
google_drive_export
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- The first time you run it, a browser window will open and you will be prompted to authorize access to your Google account:
|
|
153
|
+
- If you are not already signed in to your Google Account, sign in when prompted
|
|
154
|
+
- If you are signed in to multiple accounts, select the account to use for authorization
|
|
155
|
+
- Click Accept
|
|
156
|
+
- Authorization information is stored in the file system (`token.json`), so the next time you run it, you aren't prompted for authorization
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# google-drive-export
|
|
2
|
+
|
|
3
|
+
### Export your Google Drive data
|
|
4
|
+
|
|
5
|
+
- Copyright (c) 2025 [Corey Goldberg][github-home]
|
|
6
|
+
- License: [MIT][mit-license]
|
|
7
|
+
- Development: [GitHub][github-repo]
|
|
8
|
+
- Download/Install: [PyPI][pypi]
|
|
9
|
+
|
|
10
|
+
[github-home]: https://github.com/cgoldberg
|
|
11
|
+
[mit-license]: https://raw.githubusercontent.com/cgoldberg/google-drive-export/refs/heads/master/LICENSE
|
|
12
|
+
[github-repo]: https://github.com/cgoldberg/google-drive-export
|
|
13
|
+
[pypi]: https://pypi.org/project/google-drive-export
|
|
14
|
+
|
|
15
|
+
----
|
|
16
|
+
|
|
17
|
+
## About:
|
|
18
|
+
|
|
19
|
+
This is a command line tool for exporting your personal Google Drive files using the Google Drive API v3.
|
|
20
|
+
|
|
21
|
+
It will export all files that are owned by your account (not shared with you from other users), and
|
|
22
|
+
will not save native Google App files (Docs/Sheets/Slides/Forms/etc). Files are saved in their appropriate
|
|
23
|
+
directory structure inside a directory named `exported_files`.
|
|
24
|
+
|
|
25
|
+
For more information:
|
|
26
|
+
- [API Overview][api-overview]
|
|
27
|
+
- [REST API Reference][api-reference]
|
|
28
|
+
- [API Guides][api-guides]
|
|
29
|
+
|
|
30
|
+
[api-overview]: https://developers.google.com/workspace/drive/api
|
|
31
|
+
[api-reference]: https://developers.google.com/workspace/drive/api/reference/rest/v3
|
|
32
|
+
[api-guides]: https://developers.google.com/workspace/drive/api/guides/about-files
|
|
33
|
+
|
|
34
|
+
----
|
|
35
|
+
|
|
36
|
+
## Requirements:
|
|
37
|
+
|
|
38
|
+
- Python 3.9+
|
|
39
|
+
- Packages:
|
|
40
|
+
- google-api-python-client
|
|
41
|
+
- google-auth-httplib2
|
|
42
|
+
- google-auth-oauthlib
|
|
43
|
+
|
|
44
|
+
----
|
|
45
|
+
|
|
46
|
+
## Usage:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
usage: google_drive_export [-h] [--dir DIR]
|
|
50
|
+
|
|
51
|
+
options:
|
|
52
|
+
-h, --help show this help message and exit
|
|
53
|
+
--dir DIR output directory
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
----
|
|
57
|
+
|
|
58
|
+
## Installation:
|
|
59
|
+
|
|
60
|
+
### Create a virtual environment and install with pip
|
|
61
|
+
|
|
62
|
+
- On Linux/Mac:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
python3 -m venv venv
|
|
66
|
+
source venv/bin/activate
|
|
67
|
+
pip install google-drive-export
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- On Windows:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
py -m venv venv
|
|
74
|
+
venv\Scripts\activate
|
|
75
|
+
pip install google-drive-export
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
For more information on virtual env and pip, see:
|
|
79
|
+
- https://packaging.python.org/en/latest/tutorials/installing-packages
|
|
80
|
+
|
|
81
|
+
### Install globally with pipx
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
pipx install google-drive-export
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For more information on pipx, see:
|
|
88
|
+
- https://github.com/pypa/pipx
|
|
89
|
+
|
|
90
|
+
----
|
|
91
|
+
|
|
92
|
+
## Authorization for use with Google Drive:
|
|
93
|
+
|
|
94
|
+
After installing, you must follow these steps:
|
|
95
|
+
|
|
96
|
+
### 1. Enable the Google Drive API
|
|
97
|
+
|
|
98
|
+
- Go to the Google Cloud console (Enable access to API)
|
|
99
|
+
- https://console.cloud.google.com/flows/enableapi?apiid=drive.googleapis.com
|
|
100
|
+
- Create a Project
|
|
101
|
+
- Enable the API
|
|
102
|
+
|
|
103
|
+
### 2. Configure the OAuth Consent screen
|
|
104
|
+
|
|
105
|
+
- Go to the Google Cloud console (Branding)
|
|
106
|
+
- https://console.cloud.google.com/auth/branding
|
|
107
|
+
- Configure your Project
|
|
108
|
+
- Go to the Google Cloud console (Audience)
|
|
109
|
+
- https://console.cloud.google.com/auth/audience
|
|
110
|
+
- Add yourself as a Test user
|
|
111
|
+
|
|
112
|
+
### 3. Authorize credentials for a desktop application
|
|
113
|
+
|
|
114
|
+
- Go to the Google Cloud console (Clients)
|
|
115
|
+
- https://console.cloud.google.com/auth/clients
|
|
116
|
+
- Create a Client (Application type > Desktop app)
|
|
117
|
+
- Downloaded JSON file, rename it to credentials.json, and move it to your working directory
|
|
118
|
+
|
|
119
|
+
### 4. Run the program
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
google_drive_export
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- The first time you run it, a browser window will open and you will be prompted to authorize access to your Google account:
|
|
126
|
+
- If you are not already signed in to your Google Account, sign in when prompted
|
|
127
|
+
- If you are signed in to multiple accounts, select the account to use for authorization
|
|
128
|
+
- Click Accept
|
|
129
|
+
- Authorization information is stored in the file system (`token.json`), so the next time you run it, you aren't prompted for authorization
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: google-drive-export
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Export your Google Drive data
|
|
5
|
+
Author: Corey Goldberg
|
|
6
|
+
Maintainer: Corey Goldberg
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: homepage, https://github.com/cgoldberg/google-drive-export
|
|
9
|
+
Project-URL: source, https://github.com/cgoldberg/google-drive-export
|
|
10
|
+
Project-URL: download, https://pypi.org/project/google-drive-export
|
|
11
|
+
Keywords: google,drive,google-drive,backup,export,takeout
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: google-api-python-client==2.168.0
|
|
24
|
+
Requires-Dist: google-auth-httplib2==0.2.0
|
|
25
|
+
Requires-Dist: google-auth-oauthlib==1.2.2
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# google-drive-export
|
|
29
|
+
|
|
30
|
+
### Export your Google Drive data
|
|
31
|
+
|
|
32
|
+
- Copyright (c) 2025 [Corey Goldberg][github-home]
|
|
33
|
+
- License: [MIT][mit-license]
|
|
34
|
+
- Development: [GitHub][github-repo]
|
|
35
|
+
- Download/Install: [PyPI][pypi]
|
|
36
|
+
|
|
37
|
+
[github-home]: https://github.com/cgoldberg
|
|
38
|
+
[mit-license]: https://raw.githubusercontent.com/cgoldberg/google-drive-export/refs/heads/master/LICENSE
|
|
39
|
+
[github-repo]: https://github.com/cgoldberg/google-drive-export
|
|
40
|
+
[pypi]: https://pypi.org/project/google-drive-export
|
|
41
|
+
|
|
42
|
+
----
|
|
43
|
+
|
|
44
|
+
## About:
|
|
45
|
+
|
|
46
|
+
This is a command line tool for exporting your personal Google Drive files using the Google Drive API v3.
|
|
47
|
+
|
|
48
|
+
It will export all files that are owned by your account (not shared with you from other users), and
|
|
49
|
+
will not save native Google App files (Docs/Sheets/Slides/Forms/etc). Files are saved in their appropriate
|
|
50
|
+
directory structure inside a directory named `exported_files`.
|
|
51
|
+
|
|
52
|
+
For more information:
|
|
53
|
+
- [API Overview][api-overview]
|
|
54
|
+
- [REST API Reference][api-reference]
|
|
55
|
+
- [API Guides][api-guides]
|
|
56
|
+
|
|
57
|
+
[api-overview]: https://developers.google.com/workspace/drive/api
|
|
58
|
+
[api-reference]: https://developers.google.com/workspace/drive/api/reference/rest/v3
|
|
59
|
+
[api-guides]: https://developers.google.com/workspace/drive/api/guides/about-files
|
|
60
|
+
|
|
61
|
+
----
|
|
62
|
+
|
|
63
|
+
## Requirements:
|
|
64
|
+
|
|
65
|
+
- Python 3.9+
|
|
66
|
+
- Packages:
|
|
67
|
+
- google-api-python-client
|
|
68
|
+
- google-auth-httplib2
|
|
69
|
+
- google-auth-oauthlib
|
|
70
|
+
|
|
71
|
+
----
|
|
72
|
+
|
|
73
|
+
## Usage:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
usage: google_drive_export [-h] [--dir DIR]
|
|
77
|
+
|
|
78
|
+
options:
|
|
79
|
+
-h, --help show this help message and exit
|
|
80
|
+
--dir DIR output directory
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
----
|
|
84
|
+
|
|
85
|
+
## Installation:
|
|
86
|
+
|
|
87
|
+
### Create a virtual environment and install with pip
|
|
88
|
+
|
|
89
|
+
- On Linux/Mac:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
python3 -m venv venv
|
|
93
|
+
source venv/bin/activate
|
|
94
|
+
pip install google-drive-export
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- On Windows:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
py -m venv venv
|
|
101
|
+
venv\Scripts\activate
|
|
102
|
+
pip install google-drive-export
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
For more information on virtual env and pip, see:
|
|
106
|
+
- https://packaging.python.org/en/latest/tutorials/installing-packages
|
|
107
|
+
|
|
108
|
+
### Install globally with pipx
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
pipx install google-drive-export
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
For more information on pipx, see:
|
|
115
|
+
- https://github.com/pypa/pipx
|
|
116
|
+
|
|
117
|
+
----
|
|
118
|
+
|
|
119
|
+
## Authorization for use with Google Drive:
|
|
120
|
+
|
|
121
|
+
After installing, you must follow these steps:
|
|
122
|
+
|
|
123
|
+
### 1. Enable the Google Drive API
|
|
124
|
+
|
|
125
|
+
- Go to the Google Cloud console (Enable access to API)
|
|
126
|
+
- https://console.cloud.google.com/flows/enableapi?apiid=drive.googleapis.com
|
|
127
|
+
- Create a Project
|
|
128
|
+
- Enable the API
|
|
129
|
+
|
|
130
|
+
### 2. Configure the OAuth Consent screen
|
|
131
|
+
|
|
132
|
+
- Go to the Google Cloud console (Branding)
|
|
133
|
+
- https://console.cloud.google.com/auth/branding
|
|
134
|
+
- Configure your Project
|
|
135
|
+
- Go to the Google Cloud console (Audience)
|
|
136
|
+
- https://console.cloud.google.com/auth/audience
|
|
137
|
+
- Add yourself as a Test user
|
|
138
|
+
|
|
139
|
+
### 3. Authorize credentials for a desktop application
|
|
140
|
+
|
|
141
|
+
- Go to the Google Cloud console (Clients)
|
|
142
|
+
- https://console.cloud.google.com/auth/clients
|
|
143
|
+
- Create a Client (Application type > Desktop app)
|
|
144
|
+
- Downloaded JSON file, rename it to credentials.json, and move it to your working directory
|
|
145
|
+
|
|
146
|
+
### 4. Run the program
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
google_drive_export
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- The first time you run it, a browser window will open and you will be prompted to authorize access to your Google account:
|
|
153
|
+
- If you are not already signed in to your Google Account, sign in when prompted
|
|
154
|
+
- If you are signed in to multiple accounts, select the account to use for authorization
|
|
155
|
+
- Click Accept
|
|
156
|
+
- Authorization information is stored in the file system (`token.json`), so the next time you run it, you aren't prompted for authorization
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
google_drive_export.py
|
|
4
|
+
pyproject.toml
|
|
5
|
+
google_drive_export.egg-info/PKG-INFO
|
|
6
|
+
google_drive_export.egg-info/SOURCES.txt
|
|
7
|
+
google_drive_export.egg-info/dependency_links.txt
|
|
8
|
+
google_drive_export.egg-info/entry_points.txt
|
|
9
|
+
google_drive_export.egg-info/requires.txt
|
|
10
|
+
google_drive_export.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
google_drive_export
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# Corey Goldberg, 2025
|
|
3
|
+
# License: MIT
|
|
4
|
+
|
|
5
|
+
"""Export your Google Drive data"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import io
|
|
10
|
+
import math
|
|
11
|
+
import os
|
|
12
|
+
import shutil
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
from google.auth.transport.requests import Request
|
|
16
|
+
from google.oauth2.credentials import Credentials
|
|
17
|
+
from google_auth_oauthlib.flow import InstalledAppFlow
|
|
18
|
+
from googleapiclient.discovery import build
|
|
19
|
+
from googleapiclient.errors import HttpError
|
|
20
|
+
from googleapiclient.http import MediaIoBaseDownload
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class GDriveExport:
|
|
24
|
+
|
|
25
|
+
def __init__(self, working_dir, token_file, creds_file):
|
|
26
|
+
self.working_dir = working_dir
|
|
27
|
+
self.token_file = token_file
|
|
28
|
+
self.creds_file = creds_file
|
|
29
|
+
|
|
30
|
+
self.folder_cache = {}
|
|
31
|
+
|
|
32
|
+
self.creds = self._authenticate()
|
|
33
|
+
self.service = build("drive", "v3", credentials=self.creds)
|
|
34
|
+
self.files = self._get_files()
|
|
35
|
+
self.files_map = self._map_files()
|
|
36
|
+
|
|
37
|
+
for file_path, file_id in self.files_map.items():
|
|
38
|
+
self._download_file(file_id, file_path)
|
|
39
|
+
|
|
40
|
+
def _authenticate(self):
|
|
41
|
+
# If modifying these scopes, delete the `token.json` file
|
|
42
|
+
scopes = [
|
|
43
|
+
"https://www.googleapis.com/auth/drive.metadata.readonly",
|
|
44
|
+
"https://www.googleapis.com/auth/drive.readonly",
|
|
45
|
+
]
|
|
46
|
+
# The file token.json stores the user's access and refresh tokens,
|
|
47
|
+
# and is created automatically when the authorization flow completes
|
|
48
|
+
# for the first time
|
|
49
|
+
if os.path.exists(self.token_file):
|
|
50
|
+
creds = Credentials.from_authorized_user_file(self.token_file, scopes)
|
|
51
|
+
else:
|
|
52
|
+
creds = None
|
|
53
|
+
# If there are no (valid) credentials available, let the user log in
|
|
54
|
+
if not creds or not creds.valid:
|
|
55
|
+
if creds and creds.expired and creds.refresh_token:
|
|
56
|
+
creds.refresh(Request())
|
|
57
|
+
else:
|
|
58
|
+
flow = InstalledAppFlow.from_client_secrets_file(
|
|
59
|
+
self.creds_file, scopes
|
|
60
|
+
)
|
|
61
|
+
creds = flow.run_local_server(port=0)
|
|
62
|
+
# Save the credentials for the next run
|
|
63
|
+
with open(self.token_file, "w") as token:
|
|
64
|
+
token.write(creds.to_json())
|
|
65
|
+
return creds
|
|
66
|
+
|
|
67
|
+
def _download_file(self, file_id, file_path):
|
|
68
|
+
request = self.service.files().get_media(fileId=file_id)
|
|
69
|
+
bytes = io.BytesIO()
|
|
70
|
+
try:
|
|
71
|
+
downloader = MediaIoBaseDownload(bytes, request)
|
|
72
|
+
while True:
|
|
73
|
+
_, done = downloader.next_chunk()
|
|
74
|
+
if done:
|
|
75
|
+
break
|
|
76
|
+
except HttpError as e:
|
|
77
|
+
# Only files with binary content can be downloaded, not native
|
|
78
|
+
# Google App files (Docs/Sheets/Slides/Forms/etc)
|
|
79
|
+
if (
|
|
80
|
+
e.status_code == 403
|
|
81
|
+
and e.error_details[0]["reason"] == "fileNotDownloadable"
|
|
82
|
+
and "only files with binary content can be downloaded"
|
|
83
|
+
in e.reason.lower()
|
|
84
|
+
):
|
|
85
|
+
return None
|
|
86
|
+
else:
|
|
87
|
+
raise
|
|
88
|
+
dir_name = os.path.dirname(file_path)
|
|
89
|
+
if not os.path.exists(dir_name):
|
|
90
|
+
os.makedirs(dir_name)
|
|
91
|
+
with open(file_path, "wb") as f:
|
|
92
|
+
f.write(bytes.getvalue())
|
|
93
|
+
print(f"Downloaded: {file_path}")
|
|
94
|
+
return file_path
|
|
95
|
+
|
|
96
|
+
def _get_files(self):
|
|
97
|
+
about = self.service.about().get(fields="user").execute()
|
|
98
|
+
email = about["user"]["emailAddress"]
|
|
99
|
+
files = []
|
|
100
|
+
page_token = None
|
|
101
|
+
while True:
|
|
102
|
+
results = (
|
|
103
|
+
self.service.files()
|
|
104
|
+
.list(
|
|
105
|
+
q=f"'{email}' in owners and mimeType!='application/vnd.google-apps.folder'",
|
|
106
|
+
spaces="drive",
|
|
107
|
+
fields="nextPageToken, files(id, name, parents)",
|
|
108
|
+
pageToken=page_token,
|
|
109
|
+
)
|
|
110
|
+
.execute()
|
|
111
|
+
)
|
|
112
|
+
files.extend(results.get("files", []))
|
|
113
|
+
if not files:
|
|
114
|
+
raise RuntimeError("No files found in Google Drive")
|
|
115
|
+
page_token = results.get("nextPageToken", None)
|
|
116
|
+
if page_token is None:
|
|
117
|
+
break
|
|
118
|
+
return files
|
|
119
|
+
|
|
120
|
+
def _get_folder_path(self, folder_id):
|
|
121
|
+
path_parts = []
|
|
122
|
+
current_id = folder_id
|
|
123
|
+
while current_id:
|
|
124
|
+
if current_id in self.folder_cache:
|
|
125
|
+
folder_name, parent_id = self.folder_cache[current_id]
|
|
126
|
+
else:
|
|
127
|
+
folder = (
|
|
128
|
+
self.service.files()
|
|
129
|
+
.get(fileId=current_id, fields="name, parents")
|
|
130
|
+
.execute()
|
|
131
|
+
)
|
|
132
|
+
folder_name = folder.get("name")
|
|
133
|
+
parent_id = folder.get("parents", [None])[0]
|
|
134
|
+
self.folder_cache[current_id] = (folder_name, parent_id)
|
|
135
|
+
path_parts.insert(0, folder_name) # Add to the front
|
|
136
|
+
current_id = parent_id
|
|
137
|
+
return os.path.sep.join(path_parts[1:])
|
|
138
|
+
|
|
139
|
+
def _map_files(self):
|
|
140
|
+
files_map = {}
|
|
141
|
+
for f in self.files:
|
|
142
|
+
folder_path = self._get_folder_path(f["parents"][0])
|
|
143
|
+
file_path = os.path.join(self.working_dir, folder_path, f["name"])
|
|
144
|
+
files_map[file_path] = f["id"]
|
|
145
|
+
sorted_files_map = {key: files_map[key] for key in sorted(files_map)}
|
|
146
|
+
return sorted_files_map
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def dir_size(working_dir):
|
|
150
|
+
"""Size of a directory in bytes, including all subdirectories and files."""
|
|
151
|
+
size_bytes = 0
|
|
152
|
+
for entry in os.scandir(working_dir):
|
|
153
|
+
if entry.is_file():
|
|
154
|
+
size_bytes += entry.stat().st_size
|
|
155
|
+
elif entry.is_dir():
|
|
156
|
+
size_bytes += dir_size(entry.path)
|
|
157
|
+
return size_bytes
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def convert_size(size_bytes):
|
|
161
|
+
if size_bytes == 0:
|
|
162
|
+
return "0 B"
|
|
163
|
+
sizes = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
|
|
164
|
+
i = int(math.floor(math.log(size_bytes, 1024)))
|
|
165
|
+
p = math.pow(1024, i)
|
|
166
|
+
s = round(size_bytes / p, 2)
|
|
167
|
+
return f"{s} {sizes[i]}"
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def run(working_dir):
|
|
171
|
+
cur_dir = os.getcwd()
|
|
172
|
+
token_file = os.path.join(".", "token.json")
|
|
173
|
+
creds_file = os.path.join(".", "credentials.json")
|
|
174
|
+
if not os.path.exists(creds_file):
|
|
175
|
+
sys.exit(f"Can't find required file: {creds_file}")
|
|
176
|
+
if os.path.exists(working_dir):
|
|
177
|
+
overwrite = input(
|
|
178
|
+
f"The '{os.path.basename(working_dir)}' directory already exists. Overwrite? [y/N] "
|
|
179
|
+
).lower()
|
|
180
|
+
if overwrite in ("y", "yes"):
|
|
181
|
+
shutil.rmtree(working_dir)
|
|
182
|
+
else:
|
|
183
|
+
sys.exit("Exiting so files are not overwritten")
|
|
184
|
+
print(f"\nExporting files to: {working_dir}\n")
|
|
185
|
+
try:
|
|
186
|
+
GDriveExport(working_dir, token_file, creds_file)
|
|
187
|
+
except (HttpError, RuntimeError) as e:
|
|
188
|
+
sys.exit(f"Error: {e}")
|
|
189
|
+
size = convert_size(dir_size(working_dir))
|
|
190
|
+
print(f"\nTotal size: {size}")
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def main():
|
|
194
|
+
parser = argparse.ArgumentParser()
|
|
195
|
+
parser.add_argument("--dir", default=".", help="output directory")
|
|
196
|
+
args = parser.parse_args()
|
|
197
|
+
try:
|
|
198
|
+
working_dir = os.path.join(args.dir, "exported_files")
|
|
199
|
+
run(working_dir)
|
|
200
|
+
except KeyboardInterrupt:
|
|
201
|
+
sys.exit(1)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == "__main__":
|
|
205
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "google-drive-export"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Export your Google Drive data"
|
|
9
|
+
license = "MIT"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
authors = [{name = "Corey Goldberg"}]
|
|
12
|
+
maintainers = [{name = "Corey Goldberg"}]
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">= 3.9"
|
|
15
|
+
keywords = ["google", "drive", "google-drive", "backup", "export", "takeout"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Programming Language :: Python",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"google-api-python-client==2.168.0",
|
|
28
|
+
"google-auth-httplib2==0.2.0",
|
|
29
|
+
"google-auth-oauthlib==1.2.2",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
google_drive_export = "google_drive_export:main"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
homepage = "https://github.com/cgoldberg/google-drive-export"
|
|
37
|
+
source = "https://github.com/cgoldberg/google-drive-export"
|
|
38
|
+
download = "https://pypi.org/project/google-drive-export"
|