Modernized pytopspeed library for converting TopSpeed database files to SQLite
Project description
Pytopspeed Modernized
A modernized Python library for converting Clarion TopSpeed database files (.phd, .mod, .tps, .phz) to SQLite databases and back.
๐ Features
- Multi-format Support: Convert .phd, .mod, .tps, and .phz files
- Combined Conversion: Merge multiple TopSpeed files into a single SQLite database
- Reverse Conversion: Convert SQLite databases back to TopSpeed files
- PHZ Support: Handle zip archives containing TopSpeed files
- Progress Tracking: Real-time progress reporting and detailed logging
- Data Integrity: Preserve all data types and relationships
- CLI Interface: Easy-to-use command-line tools
- Python API: Programmatic access to all functionality
- Comprehensive Testing: 88+ unit tests and integration tests
๐ Supported File Formats
| Format | Description | Support | Converter Class |
|---|---|---|---|
.phd |
Clarion TopSpeed database files | โ Full | SqliteConverter |
.mod |
Clarion TopSpeed model files | โ Full | SqliteConverter |
.tps |
Clarion TopSpeed files | โ Full | SqliteConverter |
.phz |
Zip archives containing TopSpeed files | โ Full | PhzConverter |
๐ง File Types and Usage
Single TopSpeed Files (.phd, .mod, .tps)
Use SqliteConverter for individual TopSpeed files:
from converter.sqlite_converter import SqliteConverter
converter = SqliteConverter()
result = converter.convert('input.phd', 'output.sqlite')
Multiple TopSpeed Files (Combined Database)
Use SqliteConverter.convert_multiple() to combine multiple files into one SQLite database:
from converter.sqlite_converter import SqliteConverter
converter = SqliteConverter()
result = converter.convert_multiple(
['file1.phd', 'file2.mod', 'file3.tps'],
'combined.sqlite'
)
PHZ Files (Zip Archives)
Use PhzConverter for .phz files (zip archives containing TopSpeed files):
from converter.phz_converter import PhzConverter
converter = PhzConverter()
result = converter.convert_phz('input.phz', 'output.sqlite')
Reverse Conversion (SQLite to TopSpeed)
Use ReverseConverter to convert SQLite databases back to TopSpeed files:
from converter.reverse_converter import ReverseConverter
converter = ReverseConverter()
result = converter.convert_sqlite_to_topspeed('input.sqlite', 'output_directory/')
๐ ๏ธ Quick Start
Installation
Option 1: Install from PyPI (Recommended)
# Install directly from PyPI
pip install pytopspeed-modernized
Option 2: Install from Source
# Clone the repository
git clone https://github.com/gregeasley/pytopspeed_modernized
cd pytopspeed_modernized
# Create conda environment (optional)
conda create -n pytopspeed_modernized python=3.11
conda activate pytopspeed_modernized
# Install in development mode
pip install -e .
Basic Usage
# Convert a single .phd file to SQLite
python pytopspeed.py convert assets/TxWells.PHD output.sqlite
# Convert multiple files to a combined database
python pytopspeed.py convert assets/TxWells.PHD assets/TxWells.mod combined.sqlite
# Convert a .phz file (zip archive)
python pytopspeed.py convert assets/TxWells.phz output.sqlite
# List contents of a .phz file
python pytopspeed.py list assets/TxWells.phz
# Convert SQLite back to TopSpeed files
python pytopspeed.py reverse input.sqlite output_directory/
Python API Examples
Single TopSpeed File Conversion
from converter.sqlite_converter import SqliteConverter
# Convert a single .phd, .mod, or .tps file
converter = SqliteConverter()
results = converter.convert('input.phd', 'output.sqlite')
print(f"Success: {results['success']}, Records: {results['total_records']}")
Multiple Files to Combined Database
from converter.sqlite_converter import SqliteConverter
# Combine multiple TopSpeed files into one SQLite database
converter = SqliteConverter()
results = converter.convert_multiple(
['file1.phd', 'file2.mod'],
'combined.sqlite'
)
print(f"Files processed: {results['files_processed']}")
PHZ File Conversion (Zip Archives)
from converter.phz_converter import PhzConverter
# Convert .phz files (zip archives containing TopSpeed files)
phz_converter = PhzConverter()
results = phz_converter.convert_phz('input.phz', 'output.sqlite')
print(f"Extracted files: {results['extracted_files']}")
Reverse Conversion (SQLite to TopSpeed)
from converter.reverse_converter import ReverseConverter
# Convert SQLite database back to TopSpeed files
reverse_converter = ReverseConverter()
results = reverse_converter.convert_sqlite_to_topspeed(
'input.sqlite',
'output_directory/'
)
print(f"Generated files: {results['generated_files']}")
๐จ Common Issues and Solutions
Wrong Converter for File Type
Problem: Using SqliteConverter.convert() with a .phz file
# โ WRONG - This will fail
converter = SqliteConverter()
result = converter.convert('input.phz', 'output.sqlite') # Error: 'TPS' object has no attribute 'tables'
Solution: Use PhzConverter.convert_phz() for .phz files
# โ
CORRECT
from converter.phz_converter import PhzConverter
converter = PhzConverter()
result = converter.convert_phz('input.phz', 'output.sqlite')
File Not Found
Problem: File path doesn't exist
# โ WRONG - File doesn't exist
result = converter.convert('nonexistent.phd', 'output.sqlite')
Solution: Check file exists before conversion
import os
if os.path.exists('input.phd'):
result = converter.convert('input.phd', 'output.sqlite')
else:
print("File not found!")
Import Errors
Problem: Import path issues
# โ WRONG - Incorrect import path
from sqlite_converter import SqliteConverter # ModuleNotFoundError
Solution: Use correct import path
# โ
CORRECT
from converter.sqlite_converter import SqliteConverter
๐ Performance
Based on testing with TxWells.PHD and TxWells.mod:
- Single file conversion: ~1,300 records/second
- Combined conversion: ~1,650 records/second
- Reverse conversion: ~50,000 records/second
- Memory efficient: Configurable batch processing
- Progress tracking: Real-time progress reporting
๐ง Command Line Interface
Convert Command
python pytopspeed.py convert [OPTIONS] INPUT_FILES... OUTPUT_FILE
Options:
--batch-size BATCH_SIZE- Number of records to process in each batch (default: 1000)-v, --verbose- Enable verbose logging-q, --quiet- Suppress progress output
Reverse Command
python pytopspeed.py reverse [OPTIONS] INPUT_FILE OUTPUT_DIRECTORY
List Command
python pytopspeed.py list [OPTIONS] PHZ_FILE
๐ Documentation
Comprehensive documentation is available in the docs/ directory:
- Installation Guide - Detailed installation instructions
- API Documentation - Complete API reference
- Troubleshooting Guide - Common issues and solutions
- Developer Documentation - Development and contribution guidelines
๐งช Testing
# Run all unit tests
python -m pytest tests/unit/ -v
# Run integration tests
python -m pytest tests/integration/ -v
# Run with coverage
python -m pytest tests/ --cov=src --cov-report=html
Test Results:
- โ 88 unit tests - All passing
- โ Integration tests - End-to-end conversion testing
- โ Performance tests - Benchmarking and optimization
- โ Error handling tests - Robust error handling validation
๐ Examples
Working examples are available in the examples/ directory:
- Basic conversion - Single file conversion
- Combined conversion - Multiple file conversion
- PHZ handling - Zip archive processing
- Reverse conversion - SQLite to TopSpeed
- Round-trip conversion - Complete conversion cycle
- Custom progress tracking - Advanced progress monitoring
- Error handling - Comprehensive error handling patterns
๐๏ธ Architecture
TopSpeed Files โ Parser โ Schema Mapper โ SQLite Converter โ SQLite Database
โ โ โ โ
.phd/.mod Modernized Type Mapping Data Migration
.tps/.phz pytopspeed Field Names Batch Processing
Key Components
- TopSpeed Parser - Modernized parser for reading TopSpeed files
- Schema Mapper - Maps TopSpeed schemas to SQLite
- SQLite Converter - Handles data migration and conversion
- PHZ Converter - Processes zip archives containing TopSpeed files
- Reverse Converter - Converts SQLite back to TopSpeed files
- CLI Interface - Command-line tools for easy usage
๐ Data Type Conversion
| TopSpeed Type | SQLite Type | Notes |
|---|---|---|
| BYTE | INTEGER | 8-bit unsigned integer |
| SHORT | INTEGER | 16-bit signed integer |
| LONG | INTEGER | 32-bit signed integer |
| DATE | TEXT | Format: YYYY-MM-DD |
| TIME | TEXT | Format: HH:MM:SS |
| STRING | TEXT | Variable length text |
| DECIMAL | REAL | Floating point number |
| MEMO | BLOB | Binary large object |
| BLOB | BLOB | Binary large object |
๐ฏ Key Features
Table Name Prefixing
When converting multiple files, tables are automatically prefixed to avoid conflicts:
- .phd files โ
phd_prefix (e.g.,phd_OWNER,phd_CLASS) - .mod files โ
mod_prefix (e.g.,mod_DEPRECIATION,mod_MODID) - .tps files โ
tps_prefix - Other files โ
file_N_prefix
Column Name Sanitization
Column names are automatically sanitized for SQLite compatibility:
- Prefix removal:
TIT:PROJ_DESCRโPROJ_DESCR - Special characters:
.โ_ - Numeric prefixes:
123FIELDโ_123FIELD - Reserved words:
ORDERโORDER_TABLE
Error Handling
- Graceful degradation - Continue processing despite individual table errors
- Detailed logging - Comprehensive error reporting and debugging information
- Data preservation - Ensure data integrity even with parsing issues
- Recovery mechanisms - Automatic handling of common issues
๐ค Contributing
We welcome contributions! Please see our Developer Documentation for:
- Development setup instructions
- Code style guidelines
- Testing requirements
- Contribution process
Development Setup
# Clone and setup development environment
git clone https://github.com/gregeasley/pytopspeed_modernized
cd pytopspeed_modernized
conda create -n pytopspeed_modernized_dev python=3.11
conda activate pytopspeed_modernized_dev
pip install -e .[dev]
# Run tests
python -m pytest tests/ -v
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Based on the original pytopspeed library
- Modernized for Python 3.11 and construct 2.10+
- Enhanced with SQLite conversion and reverse conversion capabilities
- Comprehensive testing and documentation
๐ Support
- Documentation: See the
docs/directory for comprehensive guides - Examples: Check the
examples/directory for working code - Issues: Open an issue in the project repository
- Discussions: Use the project's discussion forum for questions
Ready to convert your TopSpeed files? Start with the Installation Guide and try the examples!
Project details
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 pytopspeed_modernized-1.1.0.tar.gz.
File metadata
- Download URL: pytopspeed_modernized-1.1.0.tar.gz
- Upload date:
- Size: 690.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
219f0b60d4e9b46710ec09c07c87c12695b07a5a80101227427e2ec468122c22
|
|
| MD5 |
a1bdb9970aa654c6bdfedd18a2af25a0
|
|
| BLAKE2b-256 |
b0510f0a231ba88db9385cb24e0bd08b340430a73860b4f3dd9bbde000720ad9
|
File details
Details for the file pytopspeed_modernized-1.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: pytopspeed_modernized-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 65.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3004098c47ca968db215d79a2458e97c271ab438dc0e68b0dd36362b3bd71b1
|
|
| MD5 |
34fd415af51c716061ee8a1469b66f97
|
|
| BLAKE2b-256 |
18254deaf3d19b4b740740e7f4f4eb68c710dc111560fd2a5748975a51f5a3db
|