prefect-managedfiletransfer 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.
- prefect_managedfiletransfer-0.1.0/LICENSE +202 -0
- prefect_managedfiletransfer-0.1.0/PKG-INFO +193 -0
- prefect_managedfiletransfer-0.1.0/README.md +169 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/AssetDownloadResult.py +40 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/FileMatcher.py +41 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/FileToFolderMapping.py +92 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/PathUtil.py +84 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/RCloneCommandBuilder.py +217 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/RCloneConfig.py +10 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/RCloneConfigFileBlock.py +51 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/RCloneConfigSavedInPrefect.py +19 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/RemoteAsset.py +16 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/RemoteConnectionType.py +7 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/ServerWithBasicAuthBlock.py +64 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/ServerWithPublicKeyAuthBlock.py +101 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/SortFilesBy.py +26 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/TransferType.py +6 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/__init__.py +54 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/constants.py +18 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/deploy.py +123 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/download_asset.py +392 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/download_file_task.py +95 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/ensure_space.py +27 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/flows.py +30 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/invoke_rclone.py +207 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/list_remote_assets.py +316 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/list_remote_files_task.py +88 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/main.py +364 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/rclone/osx/rclone +0 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/rclone/rclone +0 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/rclone/rclone.exe +0 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/sftp_utils.py +239 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/tasks.py +25 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/time_util.py +82 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/transfer_files_flow.py +202 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/unpack_files_flow.py +217 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/upload_asset.py +336 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/upload_file_flow.py +240 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer/upload_file_task.py +107 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer.egg-info/PKG-INFO +193 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer.egg-info/SOURCES.txt +52 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer.egg-info/dependency_links.txt +1 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer.egg-info/entry_points.txt +2 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer.egg-info/requires.txt +3 -0
- prefect_managedfiletransfer-0.1.0/prefect_managedfiletransfer.egg-info/top_level.txt +1 -0
- prefect_managedfiletransfer-0.1.0/pyproject.toml +124 -0
- prefect_managedfiletransfer-0.1.0/setup.cfg +4 -0
- prefect_managedfiletransfer-0.1.0/tests/test_block_standards.py +20 -0
- prefect_managedfiletransfer-0.1.0/tests/test_blocks.py +24 -0
- prefect_managedfiletransfer-0.1.0/tests/test_download_asset.py +366 -0
- prefect_managedfiletransfer-0.1.0/tests/test_flows.py +6 -0
- prefect_managedfiletransfer-0.1.0/tests/test_list_asset.py +302 -0
- prefect_managedfiletransfer-0.1.0/tests/test_tasks.py +24 -0
- prefect_managedfiletransfer-0.1.0/tests/test_upload_asset.py +610 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2021 Prefect Technologies, Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prefect-managedfiletransfer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Upload and download files easily between Local/SFTP/Cloud storage using rclone
|
|
5
|
+
Author-email: Alastair Crabtree <a.crabtree@imperial.ac.uk>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer
|
|
8
|
+
Keywords: prefect,file,copy,move,transfer,SFTP,rclone
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: System Administrators
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: prefect>=3.1.7
|
|
21
|
+
Requires-Dist: pydantic>=2.11.0a2
|
|
22
|
+
Requires-Dist: paramiko>=4.0.0
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# Prefect Managed File Transfer
|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<!--- Insert a cover image here -->
|
|
29
|
+
<!--- <br> -->
|
|
30
|
+
<a href="https://pypi.python.org/pypi/prefect-managedfiletransfer/" alt="PyPI version">
|
|
31
|
+
<img alt="PyPI" src="https://img.shields.io/pypi/v/prefect-managedfiletransfer?color=0052FF&labelColor=090422"></a>
|
|
32
|
+
<a href="https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer/" alt="Stars">
|
|
33
|
+
<img src="https://img.shields.io/github/stars/ImperialCollegeLondon/prefect-managedfiletransfer?color=0052FF&labelColor=090422" /></a>
|
|
34
|
+
<a href="https://pypistats.org/packages/prefect-managedfiletransfer/" alt="Downloads">
|
|
35
|
+
<img src="https://img.shields.io/pypi/dm/prefect-managedfiletransfer?color=0052FF&labelColor=090422" /></a>
|
|
36
|
+
<a href="https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer/pulse" alt="Activity">
|
|
37
|
+
<img src="https://img.shields.io/github/commit-activity/m/ImperialCollegeLondon/prefect-managedfiletransfer?color=0052FF&labelColor=090422" /></a>
|
|
38
|
+
<br>
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
Turn a prefect.io server into a managed file transfer solution. UI and Programatic creation of cron style jobs (aka Flows!) to upload and download files easily between servers. Support local, SFTP remotes plus any Cloud storage supported by rclone - so thats aws, azure, google, sharepoint, and [many more](https://rclone.org/overview/) out of the box.
|
|
42
|
+
|
|
43
|
+
Using prefect for managed file transfer means retries, logging, multi node and [high availability](https://docs.prefect.io/v3/advanced/self-hosted) come as standard - turning prefect into a reliable enterprise ready file transfer solution.
|
|
44
|
+
|
|
45
|
+
This package is not the fastest solution to move files around, but it prioritises reliability and ease of use, making it an excellent choice for replacing both quick cron job copy scripts and enterprise managed file transfer applicances.
|
|
46
|
+
|
|
47
|
+
Key features
|
|
48
|
+
|
|
49
|
+
- Copy and move files between almost any storage system easily.
|
|
50
|
+
- Reliable file moving with checksumming, file size checking etc.
|
|
51
|
+
- Smart and safe moving - settings to allow/block overwriting and to only copy files if they are new or changed.
|
|
52
|
+
- Unzip/Untar compressed folders after downloading them.
|
|
53
|
+
- Repath files as you move them.
|
|
54
|
+
- Complex filtering and ordering of files - by path, age, size etc. Pattern matching with regular expressions.
|
|
55
|
+
- Leverage Prefect.IO built in scheduling and orchestration capabilities:
|
|
56
|
+
- Transfer files on complex cron schedules
|
|
57
|
+
- notifications on success/failure - slack, email, etc
|
|
58
|
+
- Highly available server architecture - database server + multi-node workers and front ends.
|
|
59
|
+
|
|
60
|
+
Example use cases:
|
|
61
|
+
|
|
62
|
+
- Once per day SSH into my database server and copy the latest *.bkup file to a central storage location.
|
|
63
|
+
- Monitor a local network share directory for new files and automatically upload them to a cloud storage bucket.
|
|
64
|
+
- Schedule a weekly job to synchronize files between two remote servers.
|
|
65
|
+
- Move log files from a SSH available web server older than 30 days to a cold storage location.
|
|
66
|
+
- Copy file yyyy-MM-dd.zip from a remote server, where yyyy-MM-dd matches todays date, to a local directory and then unzip it.
|
|
67
|
+
- Download any file in an S3 bucket larger than 1GB and store it in a local directory.
|
|
68
|
+
|
|
69
|
+
### Installation
|
|
70
|
+
|
|
71
|
+
Install `prefect-managedfiletransfer` with `pip`. (Requires an installation of Python 3.10+.)
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install prefect-managedfiletransfer
|
|
75
|
+
# or
|
|
76
|
+
uv add prefect-managedfiletransfer
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
We recommend using a Python virtual environment manager such as uv, pipenv, conda or virtualenv.
|
|
80
|
+
|
|
81
|
+
In one (venv) terminal start a prefect server with logs enabled
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
export PREFECT_LOGGING_LEVEL="INFO"
|
|
85
|
+
export PREFECT_LOGGING_EXTRA_LOGGERS="prefect_managedfiletransfer"
|
|
86
|
+
prefect server start
|
|
87
|
+
# OR uv run prefect server start
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
There are many ways to manage infrastructure and code with prefect - here we demonstate starting a local worker:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
export PREFECT_API_URL=http://127.0.0.1:4200/api
|
|
94
|
+
# or perhaps export PREFECT_API_URL=http://host.docker.internal:4200/api
|
|
95
|
+
export PREFECT_LOGGING_EXTRA_LOGGERS="prefect_managedfiletransfer"
|
|
96
|
+
export PREFECT_LOGGING_LEVEL="INFO"
|
|
97
|
+
# [Optional] add all logs: export PREFECT_LOGGING_ROOT_LEVEL="INFO"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
prefect worker start --pool 'default-pool' --type process
|
|
101
|
+
# OR prefect worker start --pool 'default-pool' --type docker
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Install the blocks using the prefect CLI
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
prefect block register -m prefect_managedfiletransfer
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
And then deploy the flows.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# deploy the flows to run locally
|
|
115
|
+
python -m prefect_managedfiletransfer.deploy --local
|
|
116
|
+
|
|
117
|
+
# OR deploy to run with a docker image - see deploy.py
|
|
118
|
+
python -m prefect_managedfiletransfer.deploy --docker
|
|
119
|
+
|
|
120
|
+
# or a version of the above using uv run:
|
|
121
|
+
uv run python -m prefect_managedfiletransfer.deploy --local
|
|
122
|
+
uv run python -m prefect_managedfiletransfer.deploy --docker
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Visit the server UI http://localhost:4200.
|
|
126
|
+
1. Create 2 blocks, one source and one destination
|
|
127
|
+
2. On the deployments page start a `transfer_files_flow`. Configure your flow run to copy/move files between the 2 blocks.
|
|
128
|
+
|
|
129
|
+
### Installation via docker
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# run prefect server in a container port-forwarded to your local machine’s 4200 port:
|
|
133
|
+
docker run -d -p 4200:4200 prefecthq/prefect:3-latest -- prefect server start --host 0.0.0.0
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### List of components
|
|
137
|
+
|
|
138
|
+
Blocks
|
|
139
|
+
- ServerWithBasicAuthBlock - A block for connecting to a server using basic authentication.
|
|
140
|
+
- ServerWithPublicKeyAuthBlock - A block for connecting to a server using public key authentication.
|
|
141
|
+
- RCloneConfigFileBlock - A block for managing RClone configuration files.
|
|
142
|
+
|
|
143
|
+
Tasks
|
|
144
|
+
- list_remote_files_task - A task for listing files in a remote directory.
|
|
145
|
+
- download_file_task - A task for downloading a single file from a remote server.
|
|
146
|
+
- upload_file_task - A task for uploading a single file to a remote server.
|
|
147
|
+
- [TODO] delete_file_task
|
|
148
|
+
|
|
149
|
+
Flows
|
|
150
|
+
- transfer_files_flow - a fully featured flow for transferring files between different storage locations.
|
|
151
|
+
- upload_file_flow - a flow for uploading a file to a remote server. Supports pattern matching by date
|
|
152
|
+
|
|
153
|
+
### Feedback
|
|
154
|
+
|
|
155
|
+
If you encounter any bugs while using `prefect-managedfiletransfer`, feel free to open an issue in the [prefect-managedfiletransfer](https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer) repository.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
Feel free to star or watch [`prefect-managedfiletransfer`](https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer) for updates too!
|
|
159
|
+
|
|
160
|
+
### Contributing
|
|
161
|
+
|
|
162
|
+
If you'd like to help contribute to fix an issue or add a feature to `prefect-managedfiletransfer`, please [propose changes through a pull request from a fork of the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
|
|
163
|
+
|
|
164
|
+
Here are the steps:
|
|
165
|
+
|
|
166
|
+
1. [Fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository)
|
|
167
|
+
2. [Clone the forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository)
|
|
168
|
+
3. Install the repository and its dependencies:
|
|
169
|
+
```
|
|
170
|
+
# install uv first, then
|
|
171
|
+
uv sync
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
You can also access all the prefect CLI tooling inside a uv managed venv
|
|
175
|
+
```
|
|
176
|
+
uv venv
|
|
177
|
+
source .venv/bin/activate
|
|
178
|
+
prefect server start
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
4. Make desired changes
|
|
182
|
+
5. Add tests
|
|
183
|
+
6. Insert an entry to [CHANGELOG.md](https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer/blob/main/CHANGELOG.md)
|
|
184
|
+
7. Install `pre-commit` to perform quality checks prior to commit:
|
|
185
|
+
```
|
|
186
|
+
pre-commit install
|
|
187
|
+
```
|
|
188
|
+
8. use the build script to run all the checks and tests:
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
./build.sh
|
|
192
|
+
```
|
|
193
|
+
8. `git commit`, `git push`, and create a pull request
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Prefect Managed File Transfer
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<!--- Insert a cover image here -->
|
|
5
|
+
<!--- <br> -->
|
|
6
|
+
<a href="https://pypi.python.org/pypi/prefect-managedfiletransfer/" alt="PyPI version">
|
|
7
|
+
<img alt="PyPI" src="https://img.shields.io/pypi/v/prefect-managedfiletransfer?color=0052FF&labelColor=090422"></a>
|
|
8
|
+
<a href="https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer/" alt="Stars">
|
|
9
|
+
<img src="https://img.shields.io/github/stars/ImperialCollegeLondon/prefect-managedfiletransfer?color=0052FF&labelColor=090422" /></a>
|
|
10
|
+
<a href="https://pypistats.org/packages/prefect-managedfiletransfer/" alt="Downloads">
|
|
11
|
+
<img src="https://img.shields.io/pypi/dm/prefect-managedfiletransfer?color=0052FF&labelColor=090422" /></a>
|
|
12
|
+
<a href="https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer/pulse" alt="Activity">
|
|
13
|
+
<img src="https://img.shields.io/github/commit-activity/m/ImperialCollegeLondon/prefect-managedfiletransfer?color=0052FF&labelColor=090422" /></a>
|
|
14
|
+
<br>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
Turn a prefect.io server into a managed file transfer solution. UI and Programatic creation of cron style jobs (aka Flows!) to upload and download files easily between servers. Support local, SFTP remotes plus any Cloud storage supported by rclone - so thats aws, azure, google, sharepoint, and [many more](https://rclone.org/overview/) out of the box.
|
|
18
|
+
|
|
19
|
+
Using prefect for managed file transfer means retries, logging, multi node and [high availability](https://docs.prefect.io/v3/advanced/self-hosted) come as standard - turning prefect into a reliable enterprise ready file transfer solution.
|
|
20
|
+
|
|
21
|
+
This package is not the fastest solution to move files around, but it prioritises reliability and ease of use, making it an excellent choice for replacing both quick cron job copy scripts and enterprise managed file transfer applicances.
|
|
22
|
+
|
|
23
|
+
Key features
|
|
24
|
+
|
|
25
|
+
- Copy and move files between almost any storage system easily.
|
|
26
|
+
- Reliable file moving with checksumming, file size checking etc.
|
|
27
|
+
- Smart and safe moving - settings to allow/block overwriting and to only copy files if they are new or changed.
|
|
28
|
+
- Unzip/Untar compressed folders after downloading them.
|
|
29
|
+
- Repath files as you move them.
|
|
30
|
+
- Complex filtering and ordering of files - by path, age, size etc. Pattern matching with regular expressions.
|
|
31
|
+
- Leverage Prefect.IO built in scheduling and orchestration capabilities:
|
|
32
|
+
- Transfer files on complex cron schedules
|
|
33
|
+
- notifications on success/failure - slack, email, etc
|
|
34
|
+
- Highly available server architecture - database server + multi-node workers and front ends.
|
|
35
|
+
|
|
36
|
+
Example use cases:
|
|
37
|
+
|
|
38
|
+
- Once per day SSH into my database server and copy the latest *.bkup file to a central storage location.
|
|
39
|
+
- Monitor a local network share directory for new files and automatically upload them to a cloud storage bucket.
|
|
40
|
+
- Schedule a weekly job to synchronize files between two remote servers.
|
|
41
|
+
- Move log files from a SSH available web server older than 30 days to a cold storage location.
|
|
42
|
+
- Copy file yyyy-MM-dd.zip from a remote server, where yyyy-MM-dd matches todays date, to a local directory and then unzip it.
|
|
43
|
+
- Download any file in an S3 bucket larger than 1GB and store it in a local directory.
|
|
44
|
+
|
|
45
|
+
### Installation
|
|
46
|
+
|
|
47
|
+
Install `prefect-managedfiletransfer` with `pip`. (Requires an installation of Python 3.10+.)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install prefect-managedfiletransfer
|
|
51
|
+
# or
|
|
52
|
+
uv add prefect-managedfiletransfer
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
We recommend using a Python virtual environment manager such as uv, pipenv, conda or virtualenv.
|
|
56
|
+
|
|
57
|
+
In one (venv) terminal start a prefect server with logs enabled
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
export PREFECT_LOGGING_LEVEL="INFO"
|
|
61
|
+
export PREFECT_LOGGING_EXTRA_LOGGERS="prefect_managedfiletransfer"
|
|
62
|
+
prefect server start
|
|
63
|
+
# OR uv run prefect server start
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
There are many ways to manage infrastructure and code with prefect - here we demonstate starting a local worker:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
export PREFECT_API_URL=http://127.0.0.1:4200/api
|
|
70
|
+
# or perhaps export PREFECT_API_URL=http://host.docker.internal:4200/api
|
|
71
|
+
export PREFECT_LOGGING_EXTRA_LOGGERS="prefect_managedfiletransfer"
|
|
72
|
+
export PREFECT_LOGGING_LEVEL="INFO"
|
|
73
|
+
# [Optional] add all logs: export PREFECT_LOGGING_ROOT_LEVEL="INFO"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
prefect worker start --pool 'default-pool' --type process
|
|
77
|
+
# OR prefect worker start --pool 'default-pool' --type docker
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Install the blocks using the prefect CLI
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
prefect block register -m prefect_managedfiletransfer
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
And then deploy the flows.
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# deploy the flows to run locally
|
|
91
|
+
python -m prefect_managedfiletransfer.deploy --local
|
|
92
|
+
|
|
93
|
+
# OR deploy to run with a docker image - see deploy.py
|
|
94
|
+
python -m prefect_managedfiletransfer.deploy --docker
|
|
95
|
+
|
|
96
|
+
# or a version of the above using uv run:
|
|
97
|
+
uv run python -m prefect_managedfiletransfer.deploy --local
|
|
98
|
+
uv run python -m prefect_managedfiletransfer.deploy --docker
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Visit the server UI http://localhost:4200.
|
|
102
|
+
1. Create 2 blocks, one source and one destination
|
|
103
|
+
2. On the deployments page start a `transfer_files_flow`. Configure your flow run to copy/move files between the 2 blocks.
|
|
104
|
+
|
|
105
|
+
### Installation via docker
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# run prefect server in a container port-forwarded to your local machine’s 4200 port:
|
|
109
|
+
docker run -d -p 4200:4200 prefecthq/prefect:3-latest -- prefect server start --host 0.0.0.0
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### List of components
|
|
113
|
+
|
|
114
|
+
Blocks
|
|
115
|
+
- ServerWithBasicAuthBlock - A block for connecting to a server using basic authentication.
|
|
116
|
+
- ServerWithPublicKeyAuthBlock - A block for connecting to a server using public key authentication.
|
|
117
|
+
- RCloneConfigFileBlock - A block for managing RClone configuration files.
|
|
118
|
+
|
|
119
|
+
Tasks
|
|
120
|
+
- list_remote_files_task - A task for listing files in a remote directory.
|
|
121
|
+
- download_file_task - A task for downloading a single file from a remote server.
|
|
122
|
+
- upload_file_task - A task for uploading a single file to a remote server.
|
|
123
|
+
- [TODO] delete_file_task
|
|
124
|
+
|
|
125
|
+
Flows
|
|
126
|
+
- transfer_files_flow - a fully featured flow for transferring files between different storage locations.
|
|
127
|
+
- upload_file_flow - a flow for uploading a file to a remote server. Supports pattern matching by date
|
|
128
|
+
|
|
129
|
+
### Feedback
|
|
130
|
+
|
|
131
|
+
If you encounter any bugs while using `prefect-managedfiletransfer`, feel free to open an issue in the [prefect-managedfiletransfer](https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer) repository.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
Feel free to star or watch [`prefect-managedfiletransfer`](https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer) for updates too!
|
|
135
|
+
|
|
136
|
+
### Contributing
|
|
137
|
+
|
|
138
|
+
If you'd like to help contribute to fix an issue or add a feature to `prefect-managedfiletransfer`, please [propose changes through a pull request from a fork of the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
|
|
139
|
+
|
|
140
|
+
Here are the steps:
|
|
141
|
+
|
|
142
|
+
1. [Fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository)
|
|
143
|
+
2. [Clone the forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository)
|
|
144
|
+
3. Install the repository and its dependencies:
|
|
145
|
+
```
|
|
146
|
+
# install uv first, then
|
|
147
|
+
uv sync
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
You can also access all the prefect CLI tooling inside a uv managed venv
|
|
151
|
+
```
|
|
152
|
+
uv venv
|
|
153
|
+
source .venv/bin/activate
|
|
154
|
+
prefect server start
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
4. Make desired changes
|
|
158
|
+
5. Add tests
|
|
159
|
+
6. Insert an entry to [CHANGELOG.md](https://github.com/ImperialCollegeLondon/prefect-managedfiletransfer/blob/main/CHANGELOG.md)
|
|
160
|
+
7. Install `pre-commit` to perform quality checks prior to commit:
|
|
161
|
+
```
|
|
162
|
+
pre-commit install
|
|
163
|
+
```
|
|
164
|
+
8. use the build script to run all the checks and tests:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
./build.sh
|
|
168
|
+
```
|
|
169
|
+
8. `git commit`, `git push`, and create a pull request
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AssetDownloadResult:
|
|
6
|
+
"""
|
|
7
|
+
Represents the result of an asset download operation.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
success: bool,
|
|
13
|
+
file_path: Path | None,
|
|
14
|
+
download_skipped: bool = False,
|
|
15
|
+
last_modified: datetime | None = None,
|
|
16
|
+
size: int = 0,
|
|
17
|
+
error: str | None = None,
|
|
18
|
+
):
|
|
19
|
+
"""
|
|
20
|
+
Represents the result of an asset download operation.
|
|
21
|
+
:param success: True if the download was successful, False otherwise.
|
|
22
|
+
:param file_path: The path to the downloaded file, or None if the download failed.
|
|
23
|
+
:param download_skipped: True if the download was skipped because the file was not newer than the destination file.
|
|
24
|
+
:param last_modified: The last modified time of the file, if available.
|
|
25
|
+
"""
|
|
26
|
+
self.last_modified = last_modified
|
|
27
|
+
self.success = success
|
|
28
|
+
self.file_path = file_path
|
|
29
|
+
self.download_skipped = download_skipped
|
|
30
|
+
self.error = error
|
|
31
|
+
self.size = size
|
|
32
|
+
|
|
33
|
+
if not success and file_path is not None:
|
|
34
|
+
raise ValueError("If success is False, file_path must be None")
|
|
35
|
+
|
|
36
|
+
def __repr__(self):
|
|
37
|
+
if self.error:
|
|
38
|
+
return f"AssetDownloadResult(success={self.success}, error={self.error})"
|
|
39
|
+
|
|
40
|
+
return f"AssetDownloadResult(success={self.success}, file_path={self.file_path}, download_skipped={self.download_skipped}, last_modified={self.last_modified})"
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from datetime import timedelta
|
|
2
|
+
from pydantic import BaseModel, Field
|
|
3
|
+
from prefect_managedfiletransfer.SortFilesBy import SortFilesBy
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FileMatcher(BaseModel):
|
|
9
|
+
"""
|
|
10
|
+
Represents a file matcher with a source path and a pattern to match files.
|
|
11
|
+
This is used to find files in a directory that match a specific pattern.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
source_folder: Path = Field(
|
|
15
|
+
default=Path("."),
|
|
16
|
+
description="Path to the source directory to look for files.",
|
|
17
|
+
)
|
|
18
|
+
pattern_to_match: str = Field(
|
|
19
|
+
default="*",
|
|
20
|
+
description="Pattern to match files in the source directory. Supports glob patterns like '*.txt' or 'file_*.csv'.",
|
|
21
|
+
)
|
|
22
|
+
minimum_age: str | int | timedelta | None = Field(
|
|
23
|
+
default=None,
|
|
24
|
+
description="Only transfer files older than this in secs (or other time with suffix s|m|h|d|w|month|year). Default off.",
|
|
25
|
+
)
|
|
26
|
+
maximum_age: str | int | timedelta | None = Field(
|
|
27
|
+
default=None,
|
|
28
|
+
description="Only transfer files newer than this in secs (or other time with suffix s|m|h|d|w|month|year). Default off.",
|
|
29
|
+
)
|
|
30
|
+
sort: SortFilesBy = Field(
|
|
31
|
+
default=SortFilesBy.PATH_ASC,
|
|
32
|
+
description="Sort files by a specific attribute. Default is PATH_ASC.",
|
|
33
|
+
)
|
|
34
|
+
skip: int = Field(
|
|
35
|
+
default=0,
|
|
36
|
+
description="Number of files to skip in the sorted list. Default is 0.",
|
|
37
|
+
)
|
|
38
|
+
take: int | None = Field(
|
|
39
|
+
default=None,
|
|
40
|
+
description="Number of files to take from the sorted list. If None, all files are taken. Default is None.",
|
|
41
|
+
)
|