A robust and efficient tool for importing Excel(.xls and .xlsx) data to DuckDB databases with comprehensive validation and optimization.
If you don’t have uv installed, you can install it using:
# On macOS using Homebrew
brew install uv
# On macOS/Linux using curl
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows using PowerShell
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Using pip
pip install uv
# Clone the repository
git clone https://github.com/yourusername/e2duck.git
cd e2duck
# Create a virtual environment using uv
uv venv
# Activate the virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate
# Install dependencies using uv
uv pip install -r requirements.txt
# For development (includes testing tools)
uv pip install -r requirements-dev.txt
To verify that everything is installed correctly:
python -c "import pandas; import duckdb; import psutil; print('Installation successful!')"
python run.py path/to/excel_file.xlsx path/to/output.duckdb [options]
Available options:
--sample-size SIZE: Number of rows to sample for validation (default: 100)--no-safe-mode: Disable safe mode (default: enabled)from e2duck.e2duck import ExcelToDuckDB
# Initialize the converter
converter = ExcelToDuckDB(
excel_path="path/to/your/file.xlsx",
db_path="path/to/output.duckdb",
sample_size=100, # Number of rows to sample for validation
safe_mode=True # Use TEXT type for all columns to ensure data integrity
)
# Run the full import process
result = converter.run()
# Check the result
if result['success']:
print("Import successful!")
# Access validation results
validation_results = result.get('validation_results', [])
for validation in validation_results:
print(f"Sheet '{validation['sheet']}': {validation['overall_status']}")
else:
print(f"Import failed: {result.get('error', 'Unknown error')}")
The tool automatically adjusts batch sizes based on available system memory:
# Let the system determine optimal batch size based on memory
result = converter.import_data()
# Or specify a custom batch size
result = converter.import_data(batch_size=10000)
For multi-sheet Excel files, sheets are processed in parallel:
# Analysis phase uses parallel processing for multiple sheets
sheets_info = converter.analyze_excel()
| Parameter | Description | Default |
|---|---|---|
excel_path |
Path to the Excel file | Required |
db_path |
Path to the DuckDB database | Required |
sample_size |
Number of rows to sample for validation | 100 |
safe_mode |
Use TEXT type for all columns | True |
batch_size |
Number of rows to process in each batch | Dynamic based on memory |
.xlsx files process faster than .xls files due to better engine supportThe project includes comprehensive test coverage (62%) to ensure functionality and reliability:
# Run all tests
pytest tests/
# Run specific test file
pytest tests/test_initialization.py
# Run tests with coverage report
pytest --cov=e2duck tests/
# Generate detailed HTML coverage report
pytest --cov=e2duck --cov-report=html tests/
The tool provides comprehensive error handling with:
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)