{"id":28970066,"url":"https://github.com/dostuffthatmatters/circadian-scp-upload","last_synced_at":"2025-06-24T10:15:11.273Z","repository":{"id":190807730,"uuid":"664301756","full_name":"dostuffthatmatters/circadian-scp-upload","owner":"dostuffthatmatters","description":"Resumable, interruptible, SCP upload client for any files or directories generated day by day","archived":false,"fork":false,"pushed_at":"2024-10-10T13:18:53.000Z","size":245,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-24T18:42:51.560Z","etag":null,"topics":["checksum","daily","data","directories","files","library","python","scp","ssh","synchronization","time-series","upload","utilities"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/circadian-scp-upload","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dostuffthatmatters.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-07-09T14:55:27.000Z","updated_at":"2024-10-10T13:18:45.000Z","dependencies_parsed_at":"2024-01-16T00:04:11.222Z","dependency_job_id":"b85ca5e0-d5a8-48a3-8d9f-ac7703fa931a","html_url":"https://github.com/dostuffthatmatters/circadian-scp-upload","commit_stats":null,"previous_names":["dostuffthatmatters/circadian-scp-upload"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/dostuffthatmatters/circadian-scp-upload","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dostuffthatmatters%2Fcircadian-scp-upload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dostuffthatmatters%2Fcircadian-scp-upload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dostuffthatmatters%2Fcircadian-scp-upload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dostuffthatmatters%2Fcircadian-scp-upload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dostuffthatmatters","download_url":"https://codeload.github.com/dostuffthatmatters/circadian-scp-upload/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dostuffthatmatters%2Fcircadian-scp-upload/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261649895,"owners_count":23189768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["checksum","daily","data","directories","files","library","python","scp","ssh","synchronization","time-series","upload","utilities"],"created_at":"2025-06-24T10:15:06.820Z","updated_at":"2025-06-24T10:15:11.221Z","avatar_url":"https://github.com/dostuffthatmatters.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📮 Circadian SCP Upload\n\n**Resumable, interruptible, well-tested SCP upload client for any files or directories generated day by day.**\n\n[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/dostuffthatmatters/circadian-scp-upload/test.yaml?label=CI%20tests\u0026cacheSeconds=60)](https://github.com/dostuffthatmatters/circadian-scp-upload/actions/workflows/test.yaml)\n[![GitHub](https://img.shields.io/github/license/dostuffthatmatters/circadian-scp-upload?color=4c1\u0026cacheSeconds=60)](https://github.com/dostuffthatmatters/circadian-scp-upload/blob/main/LICENSE.md)\n[![PyPI - Version](https://img.shields.io/github/v/tag/dostuffthatmatters/circadian-scp-upload?label=latest%20version\u0026color=f5f5f5\u0026cacheSeconds=60)](https://pypi.org/project/circadian-scp-upload)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/circadian_scp_upload?label=supported%20Python%20versions\u0026color=f5f5f5\u0026cacheSeconds=60)](https://pypi.org/project/circadian-scp-upload)\n\n## Use Case\n\nYou have a local directory that generates daily data on your local machine. The directory looks like this:\n\n```\n📁 data-directory-1\n├── 📁 20190101\n│   ├── 📄 file1.txt\n│   ├── 📄 file2.txt\n│   └── 📄 file3.txt\n└── 📁 20190102\n    ├── 📄 file1.txt\n    ├── 📄 file2.txt\n    └── 📄 file3.txt\n```\n\nOr like this:\n\n```\n📁 data-directory-2\n├── 📄 20190101.txt\n├── 📄 20190102-a.txt\n├── 📄 20190102-b.txt\n└── 📄 20190103.txt\n```\n\nWith this tool you can:\n\n- Upload that data to a server, right **after** the day of creation\n- Mark directories as \"in progress\" on the remote server so that subsequent processing steps will not touch unfinished days of data while uploading.\n- Optionally remove the local files after the upload is complete and verified with checksums\n\nThis tool uses [SCP](https://en.wikipedia.org/wiki/Secure_copy_protocol) via the Python library [paramiko](https://github.com/paramiko/paramiko) to do that. It will write files named `.do-not-touch` in the local and remote directories during the upload process and delete them afterward.\n\nBelow is a code snippet that defines a specific directory/file naming scheme (for example, `%Y%m%d-(\\.txt|\\.csv)`). The client uses this information to tell _when_ a specific file or directory was generated. It will only upload files when at least one hour of the following day has passed.\n\n**Can't I use `rsync` or a similar CLI tool for that?**\n\nYes, of course. However, the actual copying logic of individual files or directories is just ~ 100 lines of code of this repository. The rest of this library is dedicated to being a plug-and-play solution for any Python codebase: logging, regex filters, being interruptable, in-progress markers, removing the local files after the checksums of local and remote directories are identical, etc.\n\nOne should be able to `pip install`/`pdm add`/... and call a well-documented and typed upload client class instead of manually connecting each codebase to rsync and doing all the pattern and scheduling logic repeatedly.\n\n**How do you make sure that the upload works correctly?**\n\nFirst, the whole codebase has type hints and is strictly checked with [Mypy](https://github.com/python/mypy) - even the snippet in the usage section below is tye checked with Mypy.\n\nSecondly, the date patterning is tested extensively, and the upload process of the files and directories is tested with an actual remote server by generating a bunch of sample files and directories and uploading them to that server. One can check out the output of the test runs in the [GitHub Actions](https://github.com/dostuffthatmatters/circadian-scp-upload/actions/workflows/test.yaml) of this repository - in the \"Run pytests\" step.\n\nThirdly, after the upload, the checksum of the local and the remote directories/files is compared to ensure the upload was successful. Only if those checksums match will the client delete the local files. The file removal is disabled by default and has to be actively enabled.\n\n\u003cbr/\u003e\n\n## Usage\n\nInstall into any Python `^3.10` project:\n\n```bash\npip install circadian_scp_upload\n# or\npdm add circadian_scp_upload\n```\n\nConfigure and use the upload client:\n\n```python\nimport circadian_scp_upload\n\n# Use the callbacks to customize the upload process\n# and integrate it into your own codebase. All callbacks\n# are optional and the callback object does not need to be\n# passed to the upload client. The lambda functions below\n# are the default values.\n\nupload_client_callbacks = circadian_scp_upload.UploadClientCallbacks(\n    # which directories/files to consider in the upload process; only\n    # supports %Y/%y/%m/%d - does not support parentheses in the string\n    dated_regex=r\"^\" + \"%Y%m%d\" + r\"$\",\n\n    # use your own logger instead of print statements\n    log_info=lambda message: print(f\"INFO - {message}\"),\n    log_error=lambda message: print(f\"ERROR - {message}\"),\n\n    # callback that is called periodically during the upload\n    # process to check if the upload should be aborted\n    should_abort_upload=lambda: False,\n)\n\n# teardown happens automatically when leaving the \"with\"-block\nwith circadian_scp_upload.RemoteConnection(\n    \"1.2.3.4\", \"someusername\", \"somepassword\"\n) as remote_connection:\n\n    # upload a directory full of directories \"YYYYMMDD/\"\n    circadian_scp_upload.DailyTransferClient(\n        remote_connection=remote_connection,\n        src_path=\"/path/to/local/data-directory-1\",\n        dst_path=\"/path/to/remote/data-directory-1\",\n        remove_files_after_upload=True,\n        variant=\"directories\",\n        callbacks=upload_client_callbacks,\n    ).run()\n\n    # upload a directory full of files \"YYYYMMDD.txt\"\n    circadian_scp_upload.DailyTransferClient(\n        remote_connection=remote_connection,\n        src_path=\"/path/to/local/data-directory-2\",\n        dst_path=\"/path/to/remote/data-directory-2\",\n        remove_files_after_upload=True,\n        variant=\"files\",\n        callbacks=upload_client_callbacks,\n    ).run()\n```\n\nThe client will produce an informational output wherever one directs the log output:\n\n```log\nINFO - 2024-09-17: starting to upload local directory '/tmp/circadian_scp_upload_test/2024-09-17' to remote directory '/tmp/circadian_scp_upload_test/2024-09-17'\nINFO - 2024-09-17: screening local directory\nINFO - 2024-09-17: possibly creating remote directory\nINFO - 2024-09-17: screening remote directory\nINFO - 2024-09-17: comparing local and remote directory\nINFO - 2024-09-17: found 0 synced files and 4 unsynced files\nINFO - 2024-09-17: possibly creating all remote subdirectories\nINFO - 2024-09-17: acquiring lock on local machine at \"/tmp/circadian_scp_upload_test/2024-09-17/.do-not-touch\"\nINFO - 2024-09-17: acquiring lock on remote server at \"/tmp/circadian_scp_upload_test/2024-09-17/.do-not-touch\"\nINFO - 2024-09-17: 100.0 % (4/4) uploaded (finished)\nINFO - 2024-09-17: finished removing source\nINFO - 2024-09-17: releasing lock on remote server at \"/tmp/circadian_scp_upload_test/2024-09-17/.do-not-touch\"\nINFO - 2024-09-17: releasing lock on local machine at \"/tmp/circadian_scp_upload_test/2024-09-17/.do-not-touch\"\nINFO - 2024-09-17: done (successful)\nINFO - 2024-09-18: starting to upload local directory '/tmp/circadian_scp_upload_test/2024-09-18' to remote directory '/tmp/circadian_scp_upload_test/2024-09-18'\nINFO - 2024-09-18: screening local directory\nINFO - 2024-09-18: possibly creating remote directory\nINFO - 2024-09-18: screening remote directory\nINFO - 2024-09-18: comparing local and remote directory\nINFO - 2024-09-18: found 0 synced files and 5 unsynced files\nINFO - 2024-09-18: possibly creating all remote subdirectories\nINFO - 2024-09-18: acquiring lock on local machine at \"/tmp/circadian_scp_upload_test/2024-09-18/.do-not-touch\"\nINFO - 2024-09-18: acquiring lock on remote server at \"/tmp/circadian_scp_upload_test/2024-09-18/.do-not-touch\"\nINFO - 2024-09-18: 100.0 % (5/5) uploaded (finished)\nINFO - 2024-09-18: finished removing source\nINFO - 2024-09-18: releasing lock on remote server at \"/tmp/circadian_scp_upload_test/2024-09-18/.do-not-touch\"\nINFO - 2024-09-18: releasing lock on local machine at \"/tmp/circadian_scp_upload_test/2024-09-18/.do-not-touch\"\nINFO - 2024-09-18: done (successful)\n```\n\nIf the upload takes longer than 1 minute, it logs its progress (e.g. ` 40.0 % (3/5) uploaded`) every minute.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdostuffthatmatters%2Fcircadian-scp-upload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdostuffthatmatters%2Fcircadian-scp-upload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdostuffthatmatters%2Fcircadian-scp-upload/lists"}