Upload files from URLs to cloud storage
Project description
TheLoop
A Python CLI tool for uploading files from URLs directly to cloud storage. Currently supports Google Cloud Storage (GCP) with a modular architecture designed for easy extension to other cloud providers.
Features
- 🚀 Upload files directly from URLs to cloud storage
- ☁️ Google Cloud Storage support
- 📦 Streaming uploads with progress tracking
- ⚙️ Configurable settings and logging
- 🔧 Extensible architecture for additional cloud providers
- 🛡️ Async/await for efficient stream processing
Installation
Prerequisites
- Python 3.11 or higher
- Google Cloud Storage credentials (for GCP uploads)
Install from PyPI
pip install theloop
Install from Source
git clone https://github.com/matterai/theloop.git
cd theloop
pip install -e .
Development Installation
git clone https://github.com/matterai/theloop.git
cd theloop
uv pip install -e .
uv pip install pytest pytest-cov pytest-asyncio
Usage
Basic Upload
Upload a file from a URL to Google Cloud Storage:
theloop upload "https://example.com/file.pdf" "my-bucket" "uploads/file.pdf"
Advanced Usage
Using Service Account Credentials
theloop upload \
"https://example.com/file.pdf" \
"my-bucket" \
"uploads/file.pdf" \
--credentials ~/path/to/service-account.json \
--project my-gcp-project-id
Specify Cloud Provider
theloop upload \
"https://example.com/file.pdf" \
"my-bucket" \
"uploads/file.pdf" \
--provider gcp
Configuration
View current settings:
theloop settings
Settings are stored in ~/.theloop/settings.json and include:
- Logging configuration
- Chunk size for uploads
- Default cloud provider settings
Authentication
Google Cloud Platform
-
Application Default Credentials (recommended for local development):
gcloud auth application-default login
-
Service Account Key:
theloop upload <url> <bucket> <path> --credentials /path/to/service-account.json
-
Environment Variable:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json" theloop upload <url> <bucket> <path>
Development
Project Structure
src/theloop/
├── __init__.py
├── cli.py # CLI interface using Typer
├── interfaces.py # Protocol definitions
└── services/
├── config_manager.py # Settings management
├── gcp_uploader.py # GCP-specific upload logic
└── logging_configurator.py
Setting Up Development Environment
-
Clone the repository:
git clone https://github.com/matterai/theloop.git cd theloop
-
Install dependencies:
uv pip install -e . uv pip install pytest pytest-cov pytest-asyncio
-
Run tests:
pytest
-
Run from source:
uv run python -m src.main upload <url> <bucket> <path>
Testing
The project uses pytest for testing with support for async code:
# Run all tests
pytest
# Run with coverage
pytest --cov=theloop
# Run specific test file
pytest tests/test_uploader.py
Example test structure:
import pytest
@pytest.mark.asyncio
async def test_async_upload():
# Test async upload functionality
pass
Adding a New Cloud Provider
-
Create uploader class in
services/:from theloop.interfaces import Uploader class NewProviderUploader(Uploader): async def upload_stream_async(self, url: str, bucket: str, path: str) -> None: # Implement upload logic pass
-
Update CLI in
cli.py:def _get_uploader(provider: str, settings: Settings, ...) -> Uploader: if provider == "new-provider": return NewProviderUploader(...) # ... existing providers
Code Style and Standards
- Follow PEP 8 for Python code style
- Use type hints throughout the codebase
- Implement proper error handling with user-friendly messages
- Use async/await for I/O operations
- Follow the existing patterns for configuration and logging
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes following the development guidelines
- Add tests for new functionality
- Run tests to ensure everything works:
pytest
- Commit your changes:
git commit -m "Add your feature description"
- Push to your fork:
git push origin feature/your-feature-name
- Create a Pull Request
Contribution Guidelines
- Ensure all tests pass
- Add tests for new features
- Update documentation as needed
- Follow existing code style and patterns
- Write clear commit messages
- Keep pull requests focused and small
License
This project is licensed under the MIT License - see the LICENSE section below for details.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Roadmap
- AWS S3 support
- Azure Blob Storage support
- Configuration file support
- Batch upload functionality
- Resume interrupted uploads
License Text
MIT License
Copyright (c) 2024 Vladimir Vlasiuk
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file theloop-0.1.0.tar.gz.
File metadata
- Download URL: theloop-0.1.0.tar.gz
- Upload date:
- Size: 78.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8328a35f42263106078220ed86b673671fc4a3774ba7e507845e07704ed6a45a
|
|
| MD5 |
fe0556a0250b584e57c13060d406a050
|
|
| BLAKE2b-256 |
53fcf018a8d61703fff4b4de8868c258e3857f8977b100cf2def24c8b6b5b534
|
File details
Details for the file theloop-0.1.0-py3-none-any.whl.
File metadata
- Download URL: theloop-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5223dd7431104f5aa8b5eba3971bdb439db9c58183876a88d99516456916a173
|
|
| MD5 |
5948c5f007728a779ecb0ed3f4726d0e
|
|
| BLAKE2b-256 |
6f4a4bac2e734d09cdf4ddb328356b48c29dbfb8268b06fcb2d7dc078c5bc317
|