Note: DIGY is in active development. Some features may be experimental.
DIGY is a powerful tool for executing Python code in various environments with minimal setup. It provides a consistent interface for running code locally, in Docker containers, in-memory, or on remote machines.
pip install digy
# Clone the repository
git clone https://github.com/pyfunc/digy.git
cd digy
# Install with development dependencies
pip install -e .[dev]
# Or use Poetry
poetry install
For running local scripts directly, use Python directly:
# Run a local script directly with Python
python -m examples.basic.hello_world
# For machine learning example
python -m examples.machine_learning.iris_classifier
DIGY is designed to work with git repositories. To use DIGY:
git init
git add .
git commit -m "Initial commit"
# Start interactive mode
digy local .
# Or specify the script directly (requires git repository)
digy docker examples/basic/hello_world.py
If you see errors about missing manifest files, create a basic digy.yaml
:
echo "python: 3.10" > digy.yaml
For “Failed to clone repository” errors, ensure:
digy run
digy local [REPO_URL]
Start an interactive session for a git repository.
Options:
--python VERSION
: Python version to use (e.g., 3.10)--cwd PATH
: Working directory--debug
: Enable debug outputExamples:
# Start interactive mode in current directory
digy local .
# Specify Python version
digy local --python 3.10 .
digy run <REPO_URL> <SCRIPT_PATH> [args...]
Run a specific script from a git repository.
Options:
--python VERSION
: Python version to use--debug
: Enable debug outputExamples:
# Run a script from the current repository
digy run . examples/basic/hello_world.py
# With arguments
digy run . examples/basic/script.py arg1 arg2
digy docker [options] <script> [args...]
Run a script in a Docker container.
Options:
--image IMAGE
: Docker image to use (default: python:3.9-slim)--build
: Build Docker image from Dockerfile--dockerfile PATH
: Path to Dockerfile--no-cache
: Disable Docker cache--volume SRC:DST
: Mount a volumeExamples:
# Basic usage
digy docker script.py
# Specify custom image
digy docker --image tensorflow/tensorflow script.py
# Mount volumes
digy docker -v $(pwd)/data:/data script.py
digy ram <script> [args...]
Run a script in memory for maximum performance.
Examples:
# Basic usage
digy ram script.py
# With dependencies
pip install -r requirements.txt
digy ram script.py
digy remote <user@host> <repo> <script> [args...]
Run a script on a remote machine.
Options:
--key PATH
: SSH private key--port PORT
: SSH port (default: 22)--ssh-args ARGS
: Additional SSH argumentsExamples:
# Basic usage
digy remote [email protected] github.com/owner/repo script.py
# With custom SSH key
digy remote --key ~/.ssh/id_rsa [email protected] github.com/owner/repo script.py
DIGY can be configured using environment variables or a configuration file.
Variable | Default | Description |
---|---|---|
DIGY_DEBUG |
false |
Enable debug output |
DIGY_CACHE_DIR |
~/.cache/digy |
Cache directory |
DIGY_CONFIG |
~/.config/digy/config.toml |
Config file path |
DIGY_DOCKER_IMAGE |
python:3.9-slim |
Default Docker image |
DIGY_PYTHON_BIN |
python3 |
Python interpreter |
Create ~/.config/digy/config.toml
:
[core]
debug = false
cache_dir = "~/.cache/digy"
[docker]
image = "python:3.9-slim"
build = false
no_cache = false
[remote]
port = 22
key = "~/.ssh/id_rsa"
[local]
python = "python3"
pip install -e .
poetry install
### Basic Usage
#### Interactive Mode
```bash
# Clone and interact with a repository
digy local https://github.com/octocat/Hello-World.git
# Run with a specific branch
digy local https://github.com/octocat/Hello-World.git --branch main
# Attach local files (available in interactive menu)
digy local https://github.com/pyfunc/repo.git --file ./local_script.py
# Run a specific script from a repository
digy local https://github.com/pyfunc/digy.git --script path/to/script.py
# With command-line arguments
digy local https://github.com/pyfunc/digy.git --script main.py -- --arg1 value1
# Using environment variables
DIGY_RAM_SIZE=4 digy local https://github.com/pyfunc/digy.git
# Run in a Docker container
digy docker https://github.com/pyfunc/digy.git
# Specify custom Docker image
digy docker --image python:3.12 https://github.com/pyfunc/digy.git
# Run with RAM disk for temporary files
digy ram https://github.com/pyfunc/digy.git --ram-size 2 # 2GB RAM
# Show help
digy --help
# Show version
digy --version
# Command-specific help
digy local --help
digy docker --help
digy ram --help
docker
Python package and Docker daemon runningDIGY implements a robust fallback mechanism for repository loading:
This ensures maximum compatibility across different environments and network conditions.
DIGY’s Docker integration provides isolated execution environments with these benefits:
docker
package (pip install docker
)DIGY can be configured through multiple methods (in order of precedence):
~/.config/digy/config.toml
)Variable | Default | Description |
---|---|---|
DIGY_RAM_SIZE |
1 |
RAM disk size in GB |
DIGY_DOCKER_IMAGE |
python:3.12-slim |
Default Docker image |
DIGY_LOG_LEVEL |
INFO |
Logging level (DEBUG, INFO, WARNING, ERROR) |
DIGY_CACHE_DIR |
~/.cache/digy |
Cache directory |
DIGY_TIMEOUT |
300 |
Operation timeout in seconds |
DIGY_AUTO_CLEANUP |
true |
Automatically clean up temporary files |
DIGY_GIT_BIN |
git |
Path to Git executable |
DIGY_PYTHON_BIN |
python3 |
Path to Python interpreter |
Create ~/.config/digy/config.toml
:
[core]
ram_size = 2
timeout = 600
auto_cleanup = true
log_level = "INFO"
[docker]
image = "python:3.12-slim"
use_sudo = false
[git]
bin = "/usr/bin/git"
timeout = 300
[cache]
enabled = true
max_size = "1GB"
path = "~/.cache/digy"
export GITHUB_TOKEN="your_github_token"
digy local https://github.com/username/private-repo.git
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/your_private_key
digy local [email protected]:username/private-repo.git
digy docker --network host https://github.com/pyfunc/digy.git
# Read-only mount
digy docker --mount ./config:/app/config:ro https://github.com/pyfunc/digy.git
# Read-write mount
digy docker --mount ./data:/app/data:rw https://github.com/pyfunc/digy.git
# Set environment variables
digy docker -e DEBUG=1 -e API_KEY=secret https://github.com/pyfunc/digy.git
# Load from .env file
digy docker --env-file .env https://github.com/pyfunc/digy.git
# Set memory limit (Docker only)
digy docker --memory 4g https://github.com/pyfunc/digy.git
# CPU limits
digy docker --cpus 2 https://github.com/pyfunc/digy.git
# Clean all temporary files
digy clean --all
# Remove cached repositories
digy clean --cache
# Remove Docker resources
digy clean --docker
Error: Failed to clone repository: Authentication failed
Solution:
Got permission denied while trying to connect to the Docker daemon
Solution:
docker
group:
sudo usermod -aG docker $USER
newgrp docker
sudo
(not recommended for security reasons)Error: Container ran out of memory
Solution:
digy docker --memory 8g https://github.com/pyfunc/digy.git
Enable debug logging:
digy --log-level DEBUG local https://github.com/pyfunc/digy.git
View logs:
# System logs (Linux)
journalctl -u docker.service
# Application logs
cat ~/.cache/digy/logs/digy.log
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/your-username/digy.git
cd digy
poetry install --with dev
pytest
black .
flake8
mypy .
This project is licensed under the MIT License - see the LICENSE file for details.
# hello_world.py
print("Hello, DIGY!")
digy local hello_world.py
# env_info.py
import platform
import sys
print("Python Version:", sys.version)
print("Platform:", platform.platform())
print("Current Directory:", os.getcwd())
digy local env_info.py
# data_analysis.py
import pandas as pd
# Load data
df = pd.read_csv('data.csv')
# Process data
summary = df.describe()
print(summary)
# Save results
summary.to_csv('results/summary.csv')
digy local data_analysis.py
# scraper.py
import requests
from bs4 import BeautifulSoup
def scrape(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
return {
'title': soup.title.string,
'links': [a['href'] for a in soup.find_all('a', href=True)]
}
if __name__ == '__main__':
result = scrape('https://example.com')
print(result)
pip install requests beautifulsoup4
digy local scraper.py
# train.py
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
import joblib
# Load data
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y)
# Train model
model = RandomForestClassifier()
model.fit(X_train, y_train)
# Evaluate
score = model.score(X_test, y_test)
print(f"Accuracy: {score:.2f}")
# Save model
joblib.dump(model, 'model.joblib')
pip install scikit-learn joblib
digy local train.py
For more examples, see the examples directory.
# Install from PyPI
pip install digy
# Or install from source
git clone https://github.com/pyfunc/digy
cd digy
pip install -e .
DIGY requires:
Install development dependencies:
pip install -e ".[dev]"
DIGY supports multiple execution environments:
digy local github.com/pyfunc/digy
digy remote user@host github.com/pyfunc/digy script.py
digy docker --image python:3.12 github.com/pyfunc/digy script.py
digy ram github.com/pyfunc/digy script.py
digy jvm github.com/pyfunc/digy script.py
DIGY = Dynamic Interactive Git deploY
digy(repo_url, branch='main')
Główna funkcja ładująca repozytorium i uruchamiająca interaktywne menu.
Parametry:
repo_url
(str): URL repozytorium (github.com/pyfunc/digy lub pełny URL)branch
(str): Gałąź do pobrania (domyślnie ‘main’)Zwraca:
str | None
: Ścieżka do lokalnego repozytorium lub None przy błędzieDeployer
Zarządza deploymentem aplikacji w izolowanych środowiskach.
InteractiveMenu
Zapewnia interaktywne menu z nawigacją strzałkami.
MemoryManager
Zarządza alokacją pamięci dla załadowanych repozytoriów.
from digy.loader import GitLoader
from digy.deployer import Deployer
loader = GitLoader("/custom/path")
local_path = loader.download_repo("github.com/pyfunc/digy")
deployer = Deployer(local_path)
from digy import digy
# Uruchomienie z kodu Pythona
# Lokalnie
result = digy.local('github.com/pyfunc/digy', 'script.py', ['arg1', 'arg2'])
# W pamięci RAM
result = digy.ram('github.com/pyfunc/digy', 'script.py', ['arg1', 'arg2'])
# W Dockerze
result = digy.docker('github.com/pyfunc/digy', 'script.py', ['arg1', 'arg2'])
# Wynik zawiera (success, stdout, stderr)
print(f"Sukces: {result[0]}")
print(f"Wyjście: {result[1]}")
if result[2]:
print(f"Błędy: {result[2]}")
git clone https://github.com/pyfunc/digy
cd digy
poetry install
poetry run pytest
digy/
├── digy/
│ ├── __init__.py # Główny moduł
│ ├── loader.py # Ładowanie repozytoriów
│ ├── deployer.py # Deployment and execution
│ ├── interactive.py # Interactive menu
│ ├── cli.py # Command line interface
│ ├── environment.py # Environment management
│ ├── auth.py # Authentication providers
│ └── version.py # Version information
├── tests/ # Tests
├── examples/ # Usage examples
│ ├── basic/ # Basic examples
│ ├── env/ # Environment examples
│ └── attachments/ # File attachment examples
├── pyproject.toml # Konfiguracja Poetry
└── README.md # Dokumentacja
Apache Software License - Zobacz plik LICENSE dla szczegółów.
Zapraszamy do współpracy! Prosimy o:
DIGY - Twój interaktywny asystent do deploymentu aplikacji Python! 🚀