dex-connector-google-drive 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.
Files changed (39) hide show
  1. dex_connector_google_drive-0.1.0/.gitignore +16 -0
  2. dex_connector_google_drive-0.1.0/LICENSE +21 -0
  3. dex_connector_google_drive-0.1.0/PKG-INFO +78 -0
  4. dex_connector_google_drive-0.1.0/README.md +66 -0
  5. dex_connector_google_drive-0.1.0/examples/text_copy/__init__.py +3 -0
  6. dex_connector_google_drive-0.1.0/examples/text_copy/flow.py +173 -0
  7. dex_connector_google_drive-0.1.0/examples/text_copy/integration_test.py +121 -0
  8. dex_connector_google_drive-0.1.0/examples/text_copy/main.py +16 -0
  9. dex_connector_google_drive-0.1.0/examples/text_copy/sample-input.json +1 -0
  10. dex_connector_google_drive-0.1.0/examples/text_copy/start.py +62 -0
  11. dex_connector_google_drive-0.1.0/examples/text_copy/worker.py +37 -0
  12. dex_connector_google_drive-0.1.0/pyproject.toml +38 -0
  13. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/__init__.py +65 -0
  14. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/__init__.py +2 -0
  15. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/config.py +33 -0
  16. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/connection.py +259 -0
  17. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/definitions.py +98 -0
  18. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/mock.py +299 -0
  19. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/models.py +236 -0
  20. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/refresh.py +9 -0
  21. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/steps.py +249 -0
  22. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/_generated/timestamps.py +60 -0
  23. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/client.py +311 -0
  24. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/connection.py +21 -0
  25. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/dex-connector.json +173 -0
  26. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/drivemock/__init__.py +6 -0
  27. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/json_values.py +23 -0
  28. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/models.py +31 -0
  29. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/operations.py +997 -0
  30. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/query_values.py +16 -0
  31. dex_connector_google_drive-0.1.0/src/dex_connectors/google_drive/steps.py +17 -0
  32. dex_connector_google_drive-0.1.0/tests/refresh_agreement_cases.json +1184 -0
  33. dex_connector_google_drive-0.1.0/tests/test_client.py +48 -0
  34. dex_connector_google_drive-0.1.0/tests/test_conformance.py +37 -0
  35. dex_connector_google_drive-0.1.0/tests/test_example.py +30 -0
  36. dex_connector_google_drive-0.1.0/tests/test_json_values.py +15 -0
  37. dex_connector_google_drive-0.1.0/tests/test_query_values.py +36 -0
  38. dex_connector_google_drive-0.1.0/tests/test_refresh_agreement.py +278 -0
  39. dex_connector_google_drive-0.1.0/uv.lock +866 -0
@@ -0,0 +1,16 @@
1
+ .DS_Store
2
+ __pycache__/
3
+ *.py[cod]
4
+ node_modules/
5
+ dist/
6
+ sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
7
+ /.bin/dexcli
8
+ /.bin/dex-server-zd
9
+ /sdkpython/.dexcli-data/
10
+ site/.catalog.yaml
11
+ coverage/
12
+ *.out
13
+ *.test
14
+ go.work
15
+ go.work.sum
16
+ .idea/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Super Durable
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,78 @@
1
+ Metadata-Version: 2.5
2
+ Name: dex-connector-google-drive
3
+ Version: 0.1.0
4
+ Summary: Dex-native Google Drive connector
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: dex-connectors-sdk==0.7.0
9
+ Requires-Dist: dex-python-sdk>=1.28.0
10
+ Requires-Dist: httpx>=0.27
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Google Drive Python connector
14
+
15
+ This package implements `searchFiles`, `getFile`, `readFileText`, and
16
+ `uploadFile` for Dex Python applications. Both Google OAuth and Workspace
17
+ domain delegation use manifest-generated credential refresh and Dex project
18
+ storage. Configure `google / google-drive-files` in Dex Web **Connections**,
19
+ following the [connector authorization guide](../README.md). Do not put
20
+ access or refresh tokens in Flow input.
21
+ File timestamps follow Go JSON timestamp validation, including rejection of
22
+ hour 24 before a file Result is stored.
23
+
24
+ The [text copy example](examples/text_copy) searches by exact source name,
25
+ reads bounded UTF-8 text, uploads one copy behind a durable dispatch fence,
26
+ and reads its metadata back. It wires only the successful branch of each
27
+ operation. Save `connections.json` from Dex Web and use its path below.
28
+
29
+ From `connectors/google/drive/python`, generate the strict FDG 2.0 graph:
30
+
31
+ ```sh
32
+ uv sync --locked
33
+ dexcli visualize examples/text_copy/flow.py --language python \
34
+ --schema-version 2.0 --json --out build/google-drive-python-text-copy \
35
+ --python .venv/bin/python
36
+ ```
37
+
38
+ Start Dex with the generated graph, then run the Worker and Client entrypoints
39
+ from separate terminals:
40
+
41
+ ```sh
42
+ dexcli dev -flow-rendering-dir build
43
+ ```
44
+
45
+ ```sh
46
+ DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
47
+ DEX_CONNECTOR_CONFIG_FILE=/path/to/connections.json \
48
+ uv run python -m examples.text_copy.main
49
+ ```
50
+
51
+ ```sh
52
+ DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
53
+ DEX_CONNECTOR_CONFIG_FILE=/path/to/connections.json \
54
+ uv run python -m examples.text_copy.start \
55
+ google-drive-text-copy-001 examples/text_copy/sample-input.json
56
+ ```
57
+
58
+ Use a new Flow ID for each start. The source must be a text file or a Google
59
+ Workspace document with a text export. The copy is written to My Drive root.
60
+ The example's `CONNECTION_NAME` remains `google-drive-files`.
61
+
62
+ The Go-recorded provider scenarios and generated refresh agreement run with:
63
+
64
+ ```sh
65
+ uv run pytest
66
+ ```
67
+
68
+ With a real `dexcli dev` service at `DEX_FLOW_SERVICE_ADDRESS`, run the
69
+ checked-in Worker and Client integration test:
70
+
71
+ ```sh
72
+ DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
73
+ uv run pytest examples/text_copy/integration_test.py
74
+ ```
75
+
76
+ That test binds its fake provider to an OS-assigned free port. The OAuth consent
77
+ and Workspace delegated authorization flows against real Google accounts have
78
+ not been verified for this Python port.
@@ -0,0 +1,66 @@
1
+ # Google Drive Python connector
2
+
3
+ This package implements `searchFiles`, `getFile`, `readFileText`, and
4
+ `uploadFile` for Dex Python applications. Both Google OAuth and Workspace
5
+ domain delegation use manifest-generated credential refresh and Dex project
6
+ storage. Configure `google / google-drive-files` in Dex Web **Connections**,
7
+ following the [connector authorization guide](../README.md). Do not put
8
+ access or refresh tokens in Flow input.
9
+ File timestamps follow Go JSON timestamp validation, including rejection of
10
+ hour 24 before a file Result is stored.
11
+
12
+ The [text copy example](examples/text_copy) searches by exact source name,
13
+ reads bounded UTF-8 text, uploads one copy behind a durable dispatch fence,
14
+ and reads its metadata back. It wires only the successful branch of each
15
+ operation. Save `connections.json` from Dex Web and use its path below.
16
+
17
+ From `connectors/google/drive/python`, generate the strict FDG 2.0 graph:
18
+
19
+ ```sh
20
+ uv sync --locked
21
+ dexcli visualize examples/text_copy/flow.py --language python \
22
+ --schema-version 2.0 --json --out build/google-drive-python-text-copy \
23
+ --python .venv/bin/python
24
+ ```
25
+
26
+ Start Dex with the generated graph, then run the Worker and Client entrypoints
27
+ from separate terminals:
28
+
29
+ ```sh
30
+ dexcli dev -flow-rendering-dir build
31
+ ```
32
+
33
+ ```sh
34
+ DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
35
+ DEX_CONNECTOR_CONFIG_FILE=/path/to/connections.json \
36
+ uv run python -m examples.text_copy.main
37
+ ```
38
+
39
+ ```sh
40
+ DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
41
+ DEX_CONNECTOR_CONFIG_FILE=/path/to/connections.json \
42
+ uv run python -m examples.text_copy.start \
43
+ google-drive-text-copy-001 examples/text_copy/sample-input.json
44
+ ```
45
+
46
+ Use a new Flow ID for each start. The source must be a text file or a Google
47
+ Workspace document with a text export. The copy is written to My Drive root.
48
+ The example's `CONNECTION_NAME` remains `google-drive-files`.
49
+
50
+ The Go-recorded provider scenarios and generated refresh agreement run with:
51
+
52
+ ```sh
53
+ uv run pytest
54
+ ```
55
+
56
+ With a real `dexcli dev` service at `DEX_FLOW_SERVICE_ADDRESS`, run the
57
+ checked-in Worker and Client integration test:
58
+
59
+ ```sh
60
+ DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:8801 \
61
+ uv run pytest examples/text_copy/integration_test.py
62
+ ```
63
+
64
+ That test binds its fake provider to an OS-assigned free port. The OAuth consent
65
+ and Workspace delegated authorization flows against real Google accounts have
66
+ not been verified for this Python port.
@@ -0,0 +1,3 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Runnable Google Drive text copy Flow."""
@@ -0,0 +1,173 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Resolve a Drive file, read its text, upload a copy, and read back metadata."""
4
+
5
+ from dataclasses import dataclass, field
6
+
7
+ import dex
8
+ from dex_connectors.sdk import MutationResult, QueryResult
9
+
10
+ from dex_connectors.google_drive import (
11
+ Connection,
12
+ File,
13
+ GetFileInput,
14
+ ReadFileTextInput,
15
+ ReadFileTextOutput,
16
+ SearchFilesInput,
17
+ SearchFilesOutput,
18
+ UploadFileInput,
19
+ UploadFileOutput,
20
+ new_get_file_step,
21
+ new_read_file_text_step,
22
+ new_search_files_step,
23
+ new_upload_file_step,
24
+ )
25
+
26
+ CONNECTION_NAME = "google-drive-files"
27
+ FLOW_TYPE = "GoogleDriveTextCopyPython"
28
+
29
+
30
+ @dataclass(frozen=True, slots=True)
31
+ class TextCopyInput:
32
+ """Safe file names supplied when the Flow starts."""
33
+
34
+ source_name: str = field(metadata={"dex_json_name": "sourceName"})
35
+ copy_name: str = field(metadata={"dex_json_name": "copyName"})
36
+
37
+
38
+ request_attribute = dex.Attribute("google-drive-python-text-copy-request", TextCopyInput)
39
+
40
+
41
+ # dex:group group-id:google-drive group-label:"Google Drive"
42
+ # dex:explanation text:"Validate and retain source and copy file names."
43
+ class PrepareTextCopy(dex.Step[TextCopyInput]):
44
+ """Persist safe names before any provider call."""
45
+
46
+ def execute(self, context: dex.Context, input: TextCopyInput) -> dex.StepDecision:
47
+ """Begin the exact-name search when both names are usable."""
48
+ if not input.source_name.strip() or not input.copy_name.strip():
49
+ return dex.force_fail("sourceName and copyName are required")
50
+ request_attribute.set(context, input)
51
+ return dex.go_to(dex.StepRef("SearchSourceFile"), input)
52
+
53
+
54
+ # dex:group group-id:google-drive group-label:"Google Drive"
55
+ # dex:explanation text:"Choose one exact-name source file and read its text."
56
+ class SelectSourceFile(dex.Step[QueryResult[SearchFilesOutput]]):
57
+ """Choose the first file returned by the exact-name search."""
58
+
59
+ def execute(self, context: dex.Context, input: QueryResult[SearchFilesOutput]) -> dex.StepDecision:
60
+ """Pass the provider file ID to the text read Step."""
61
+ if len(input.value.files) != 1 or input.value.next_page_token or input.value.is_incomplete_search:
62
+ return dex.force_fail("sourceName must resolve to exactly one file")
63
+ return dex.go_to(dex.StepRef("ReadSourceText"), ReadFileTextInput(input.value.files[0].id))
64
+
65
+
66
+ # dex:group group-id:google-drive group-label:"Google Drive"
67
+ # dex:explanation text:"Prepare a text copy from the bounded source content."
68
+ class PrepareUpload(dex.Step[QueryResult[ReadFileTextOutput]]):
69
+ """Map the bounded text result to one upload request."""
70
+
71
+ def execute(self, context: dex.Context, input: QueryResult[ReadFileTextOutput]) -> dex.StepDecision:
72
+ """Continue to the fenced upload Mutation."""
73
+ request = request_attribute.get(context)
74
+ return dex.go_to(
75
+ dex.StepRef("UploadTextCopy"),
76
+ UploadFileInput(
77
+ name=request.copy_name, mime_type=input.value.text_mime_type, text_content=input.value.text
78
+ ),
79
+ )
80
+
81
+
82
+ # dex:group group-id:google-drive group-label:"Google Drive"
83
+ # dex:explanation text:"Return the newly uploaded file metadata."
84
+ class CompleteTextCopy(dex.Step[QueryResult[File]]):
85
+ """Complete with the provider's full copy metadata."""
86
+
87
+ def execute(self, context: dex.Context, input: QueryResult[File]) -> dex.StepDecision:
88
+ """Return the verified uploaded file."""
89
+ return dex.graceful_complete(input.value)
90
+
91
+
92
+ class TextCopyFlow(dex.Flow[TextCopyInput]):
93
+ """Copy one uniquely named Drive text file into the authorized Drive."""
94
+
95
+ def __init__(self, connection: Connection) -> None:
96
+ if connection is None or connection.reference.name != CONNECTION_NAME:
97
+ raise ValueError("Google Drive text copy requires the static connection")
98
+ self.prepare = PrepareTextCopy()
99
+ self.select = SelectSourceFile()
100
+ self.prepare_upload = PrepareUpload()
101
+ self.complete = CompleteTextCopy()
102
+ self.search = new_search_files_step(
103
+ step_type="SearchSourceFile",
104
+ step_input_type=TextCopyInput,
105
+ annotations={
106
+ "groupId": "google-drive",
107
+ "groupLabel": "Google Drive",
108
+ "explanation": "Find exactly one source file by name.",
109
+ },
110
+ connection=connection,
111
+ connection_name=CONNECTION_NAME,
112
+ map_to_operation_input=lambda request: SearchFilesInput(name=request.source_name),
113
+ found=self.select,
114
+ )
115
+ self.read = new_read_file_text_step(
116
+ step_type="ReadSourceText",
117
+ step_input_type=ReadFileTextInput,
118
+ annotations={
119
+ "groupId": "google-drive",
120
+ "groupLabel": "Google Drive",
121
+ "explanation": "Read bounded UTF-8 source content.",
122
+ },
123
+ connection=connection,
124
+ connection_name=CONNECTION_NAME,
125
+ map_to_operation_input=lambda request: request,
126
+ read=self.prepare_upload,
127
+ )
128
+ self.get_copy = new_get_file_step(
129
+ step_type="ReadBackTextCopy",
130
+ step_input_type=MutationResult[UploadFileOutput],
131
+ annotations={
132
+ "groupId": "google-drive",
133
+ "groupLabel": "Google Drive",
134
+ "explanation": "Read back the uploaded copy's full metadata.",
135
+ },
136
+ connection=connection,
137
+ connection_name=CONNECTION_NAME,
138
+ map_to_operation_input=lambda result: GetFileInput(result.value.file.id),
139
+ found=self.complete,
140
+ )
141
+ self.upload = new_upload_file_step(
142
+ step_type="UploadTextCopy",
143
+ step_input_type=UploadFileInput,
144
+ annotations={
145
+ "groupId": "google-drive",
146
+ "groupLabel": "Google Drive",
147
+ "explanation": "Upload one text copy with durable duplicate protection.",
148
+ },
149
+ connection=connection,
150
+ connection_name=CONNECTION_NAME,
151
+ map_to_operation_input=lambda request: request,
152
+ uploaded=self.get_copy,
153
+ )
154
+
155
+ def get_flow_type(self) -> str:
156
+ """Return the stable Dex Flow identity."""
157
+ return "GoogleDriveTextCopyPython"
158
+
159
+ def get_steps(self) -> dex.StepList[TextCopyInput]:
160
+ """Register local and provider Steps in execution order."""
161
+ return dex.StepList.start_step(self.prepare).other_steps(
162
+ self.search,
163
+ self.select,
164
+ self.read,
165
+ self.prepare_upload,
166
+ self.upload,
167
+ self.get_copy,
168
+ self.complete,
169
+ )
170
+
171
+ def get_persistence_schema(self) -> dex.PersistenceSchema:
172
+ """Register the request Attribute consumed by the upload preparation."""
173
+ return dex.PersistenceSchema.of(request_attribute)
@@ -0,0 +1,121 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Run all four operations through a real Dex Worker and Client."""
4
+
5
+ import asyncio
6
+ import os
7
+ import tempfile
8
+ import threading
9
+ from datetime import timedelta
10
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
11
+ from pathlib import Path
12
+ from uuid import uuid4
13
+
14
+ import dex
15
+ import pytest
16
+ from dex_connectors.sdk import ConnectionRef, SecretString, StaticCredentialProvider
17
+
18
+ from dex_connectors.google_drive import (
19
+ Client,
20
+ Config,
21
+ Credentials,
22
+ File,
23
+ new_connection,
24
+ )
25
+
26
+ from .flow import CONNECTION_NAME, TextCopyFlow, TextCopyInput
27
+
28
+
29
+ @pytest.mark.asyncio
30
+ async def test_text_copy_uses_real_dex_worker_and_all_provider_operations() -> None:
31
+ """Verify search, bounded read, fenced upload, and metadata read-back."""
32
+ server_address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
33
+ requests: list[tuple[str, str]] = []
34
+
35
+ class Provider(BaseHTTPRequestHandler):
36
+ def log_message(self, format: str, *args: object) -> None:
37
+ pass # The test records only the request method and path.
38
+
39
+ def respond(self, status: int, body: bytes) -> None:
40
+ self.send_response(status)
41
+ self.send_header("Content-Type", "application/json")
42
+ self.send_header("Content-Length", str(len(body)))
43
+ self.end_headers()
44
+ self.wfile.write(body)
45
+
46
+ def do_GET(self) -> None:
47
+ requests.append(("GET", self.path))
48
+ if self.path.startswith("/drive/v3/files?") and "appProperties" in self.path:
49
+ self.respond(200, b'{"files":[]}')
50
+ elif self.path.startswith("/drive/v3/files?"):
51
+ self.respond(
52
+ 200, b'{"files":[{"id":"source_file","name":"Ops Policy","mimeType":"text/plain"}]}'
53
+ )
54
+ elif self.path.startswith("/drive/v3/files/source_file?") and "alt=media" in self.path:
55
+ self.respond(200, b"Hello")
56
+ elif self.path.startswith("/drive/v3/files/source_file?"):
57
+ self.respond(
58
+ 200, b'{"id":"source_file","name":"Ops Policy","mimeType":"text/plain","size":"5"}'
59
+ )
60
+ elif self.path.startswith("/drive/v3/files/copied_file?"):
61
+ self.respond(
62
+ 200,
63
+ b'{"id":"copied_file","name":"Ops Policy copy.txt","mimeType":"text/plain","size":"5"}',
64
+ )
65
+ else:
66
+ self.respond(404, b"{}")
67
+
68
+ def do_POST(self) -> None:
69
+ requests.append(("POST", self.path))
70
+ length = int(self.headers["Content-Length"])
71
+ body = self.rfile.read(length)
72
+ assert b"Hello" in body
73
+ self.respond(
74
+ 200, b'{"id":"copied_file","name":"Ops Policy copy.txt","mimeType":"text/plain","size":"5"}'
75
+ )
76
+
77
+ provider = ThreadingHTTPServer(("127.0.0.1", 0), Provider)
78
+ provider_thread = threading.Thread(target=provider.serve_forever, daemon=True)
79
+ provider_thread.start()
80
+ reference = ConnectionRef("google", CONNECTION_NAME)
81
+ client = Client(
82
+ Config(endpoint=f"http://127.0.0.1:{provider.server_port}"),
83
+ StaticCredentialProvider({reference: Credentials(access_token=SecretString("inert-token"))}),
84
+ )
85
+ connection = new_connection(client, reference)
86
+ try:
87
+ with tempfile.TemporaryDirectory(prefix="google-drive-python-dex-blobs-") as cache_directory:
88
+ flow = TextCopyFlow(connection)
89
+ registry = dex.Registry([flow], allow_async_handlers=True)
90
+ cache = dex.open_blob_cache(dex.BlobCacheConfig(str(Path(cache_directory) / "blobs"), 1 << 24))
91
+ try:
92
+ worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=server_address))
93
+ worker_task = asyncio.create_task(worker.start())
94
+ try:
95
+ await worker.wait_pull_registered(timeout=15)
96
+ async with dex.AsyncClient(
97
+ registry, cache, dex.ClientOptions(server_address=server_address)
98
+ ) as dex_client:
99
+ flow_id = f"google-drive-python-text-copy-{uuid4().hex}"
100
+ await dex_client.start_flow(
101
+ flow, flow_id, TextCopyInput("Ops Policy", "Ops Policy copy.txt")
102
+ )
103
+ result = await asyncio.wait_for(
104
+ dex_client.wait_for_flow(flow_id, timedelta(seconds=30)), 40
105
+ )
106
+ assert result.status == dex.FlowStatus.COMPLETED, result.error_message
107
+ copy = result.single_output(File)
108
+ assert copy.id == "copied_file"
109
+ assert copy.name == "Ops Policy copy.txt"
110
+ finally:
111
+ await worker.stop()
112
+ await worker_task
113
+ finally:
114
+ cache.close()
115
+ finally:
116
+ await connection.aclose()
117
+ provider.shutdown()
118
+ provider.server_close()
119
+ provider_thread.join(timeout=5)
120
+ assert len(requests) == 6
121
+ assert [method for method, _ in requests] == ["GET", "GET", "GET", "GET", "POST", "GET"]
@@ -0,0 +1,16 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Start the Google Drive text copy Worker."""
4
+
5
+ import asyncio
6
+
7
+ from .worker import run_worker
8
+
9
+
10
+ def main() -> None:
11
+ """Serve the registered Dex Flow."""
12
+ asyncio.run(run_worker())
13
+
14
+
15
+ if __name__ == "__main__":
16
+ main()
@@ -0,0 +1 @@
1
+ {"sourceName":"Ops Policy","copyName":"Ops Policy copy.txt"}
@@ -0,0 +1,62 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Start a Google Drive text copy Flow from a JSON input file."""
4
+
5
+ import argparse
6
+ import asyncio
7
+ import os
8
+ import tempfile
9
+ from pathlib import Path
10
+
11
+ import dex
12
+ from dex_connectors.sdk.projectconfig import load_from_environment
13
+
14
+ from dex_connectors.google_drive import new_project_connection
15
+
16
+ from .flow import CONNECTION_NAME, TextCopyFlow, TextCopyInput
17
+
18
+
19
+ async def start_text_copy(flow_id: str, input_file: Path) -> str:
20
+ """Decode the safe start input and submit it to a registered Dex Worker."""
21
+ encoded_input = input_file.read_bytes()
22
+ if len(encoded_input) > 65_536:
23
+ raise ValueError("text copy input exceeds 65536 bytes")
24
+ request = (
25
+ dex.CodecRegistry()
26
+ .resolve(TextCopyInput)
27
+ .decode(dex.Value(dex.WireKind.JSON, encoded_input.decode("utf-8")))
28
+ )
29
+ project = await load_from_environment()
30
+ connection = new_project_connection(project, CONNECTION_NAME)
31
+ try:
32
+ flow = TextCopyFlow(connection)
33
+ registry = dex.Registry([flow], allow_async_handlers=True)
34
+ with tempfile.TemporaryDirectory(prefix="google-drive-python-start-blobs-") as cache_directory:
35
+ cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 24))
36
+ try:
37
+ async with dex.AsyncClient(
38
+ registry,
39
+ cache,
40
+ dex.ClientOptions(
41
+ server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")
42
+ ),
43
+ ) as client:
44
+ return await client.start_flow(flow, flow_id, request)
45
+ finally:
46
+ cache.close()
47
+ finally:
48
+ await connection.aclose()
49
+ await project.close()
50
+
51
+
52
+ def main() -> None:
53
+ """Accept a unique Flow ID and JSON input path."""
54
+ parser = argparse.ArgumentParser(description="Start a Google Drive text copy Flow")
55
+ parser.add_argument("flow_id")
56
+ parser.add_argument("input_file", type=Path)
57
+ arguments = parser.parse_args()
58
+ print(asyncio.run(start_text_copy(arguments.flow_id, arguments.input_file)))
59
+
60
+
61
+ if __name__ == "__main__":
62
+ main()
@@ -0,0 +1,37 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Serve the Google Drive text copy Flow with a Dex Worker."""
4
+
5
+ import os
6
+ import tempfile
7
+ from pathlib import Path
8
+
9
+ import dex
10
+ from dex_connectors.sdk.projectconfig import load_from_environment
11
+
12
+ from dex_connectors.google_drive import new_project_connection
13
+
14
+ from .flow import CONNECTION_NAME, TextCopyFlow
15
+
16
+
17
+ async def run_worker() -> None:
18
+ """Load the named connection and serve the Flow until shutdown."""
19
+ project = await load_from_environment()
20
+ connection = new_project_connection(project, CONNECTION_NAME)
21
+ cache_directory = os.environ.get(
22
+ "DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-google-drive-python-text-copy-blobs")
23
+ )
24
+ cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
25
+ try:
26
+ registry = dex.Registry([TextCopyFlow(connection)], allow_async_handlers=True)
27
+ worker = dex.AsyncWorker(
28
+ registry,
29
+ cache,
30
+ dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
31
+ )
32
+ async with worker:
33
+ await worker.start()
34
+ finally:
35
+ cache.close()
36
+ await connection.aclose()
37
+ await project.close()
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "dex-connector-google-drive"
7
+ version = "0.1.0"
8
+ description = "Dex-native Google Drive connector"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ dependencies = ["dex-connectors-sdk==0.7.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
14
+
15
+ [dependency-groups]
16
+ dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7"]
17
+
18
+ [tool.hatch.build.targets.wheel]
19
+ packages = ["src/dex_connectors"]
20
+
21
+ [tool.pytest.ini_options]
22
+ testpaths = ["tests"]
23
+ pythonpath = [".", "src"]
24
+ asyncio_mode = "auto"
25
+ asyncio_default_fixture_loop_scope = "function"
26
+
27
+ [tool.mypy]
28
+ python_version = "3.11"
29
+ strict = true
30
+ mypy_path = "src"
31
+ explicit_package_bases = true
32
+
33
+ [tool.ruff]
34
+ target-version = "py311"
35
+ line-length = 110
36
+
37
+ [tool.ruff.lint]
38
+ select = ["E", "F", "I", "UP", "B"]