dfdr/examples/basic_usage.py

53 lines
1.5 KiB
Python
Raw Permalink Normal View History

2025-11-29 07:35:29 +01:00
#!/usr/bin/env python3
"""
Basic usage example for dfdr.
This example demonstrates how to use dfdr programmatically.
"""
from pathlib import Path
import tempfile
from dfdr.config import Config
from dfdr.storage import Storage
def main():
"""Demonstrate basic dfdr usage."""
# Create a temporary directory for this example
with tempfile.TemporaryDirectory() as tmpdir:
print(f"Working in temporary directory: {tmpdir}")
# Initialize configuration
config = Config(Path(tmpdir))
print("✓ Initialized dfdr configuration")
# Add a remote (this would be a real URL in practice)
config.add_remote("example", "https://data.example.com/")
print("✓ Added remote 'example'")
# List remotes
remotes = config.list_remotes()
print(f"✓ Configured remotes: {list(remotes.keys())}")
# Initialize storage
storage = Storage(config)
print("✓ Initialized storage manager")
# In a real scenario, you would:
# 1. storage.add_file("example", "datasets/sales.csv")
# 2. storage.fetch_all()
# 3. storage.pull_all()
# 4. status = storage.get_status()
print("\n📁 Directory structure created:")
for path in sorted(Path(tmpdir).rglob("*")):
if path.is_file():
rel_path = path.relative_to(tmpdir)
print(f" {rel_path}")
if __name__ == "__main__":
main()