SQL Splitter 🚀
A high-performance command-line tool designed to split massive SQL dump files into smaller, manageable chunks. Unlike simple line-based splitters, SQL Splitter respects SQL statement boundaries (using separators like ;) to ensure each chunk remains a valid SQL script.
✨ Features
- Smart Splitting: Splits files based on size while respecting SQL statement integrity.
- Compression: Optionally remove comments and empty lines to reduce chunk size.
- Configurable: Define custom separators, single-line comment markers, and multi-line comment markers.
- Fast & Efficient: Processes files line-by-line using streaming I/O, minimizing memory usage for multi-gigabyte files.
🛠 Prerequisites
- Python: 3.13 or higher.
- uv: Recommended for dependency management (fast, reliable).
🚀 Installation & Setup
We use uv for easy environment management.
-
Clone the repository:
git clone <repository-url> cd sql_splitter
-
Sync dependencies:
uv sync
📖 Usage Guide
Command Line Arguments
Run the tool using uv run psql-splitter.
| Argument | Long Flag | Required | Default | Description |
|---|---|---|---|---|
-f |
N/A | Yes | - | Path to the source SQL file. |
-n |
N/A | Yes | - | Number of chunks to split the file into. |
-s |
N/A | No | ; |
SQL statement separator. |
-c |
N/A | No | -- |
Single-line comment character. |
-m |
N/A | No | /* |
Multi-line comment character start. |
-z |
N/A | No | False | Flag to compress output (removes empty lines/comments). |
Examples
Basic split into 5 chunks:
uv run psql-splitter -f big_dump.sql -n 5
Split with compression and custom separator:
uv run psql-splitter -f my_data.sql -n 3 -s "$$" -z
🧑💻 Developer Guide
If you are a developer joining the project, here is how you can work with the codebase.
Project Structure
.
├── main.py # CLI Entry point
├── Makefile # Automated task runner
├── pyproject.toml # Project metadata and dependencies
├── src/
│ ├── splitter.py # Core splitting logic
│ └── tests/ # Unit tests
└── README.md # This file
Automation with Makefile
The project includes a Makefile for common tasks:
-
Run Example:
make runRuns the splitter on a
test_dump.sqlfile (cleans previous chunks first). -
Run Tests:
make test
Executes the test suite using
pytest. -
Cleanup:
make cleanRemoves all generated
.sqlchunks (files matching[0-9]*.sql). -
Help:
make help
Lists available commands.
Running Tests Manually
You can also run tests directly via uv:
uv run pytest src/tests -v
📝 How it works
- Size Calculation: The tool calculates the total file size and determines a target chunk size by dividing it by
-n. - Streaming Read: It reads the input file line-by-line to handle extremely large files without filling up RAM.
- Statement Boundary: It only closes a chunk if it has exceeded the target size and the current line ends with the specified separator (
-s). - Compression Mode: When
-zis enabled, the tool skips lines that are empty or start with the specified comment characters (-cor-m).
📄 License
Metadata
Release files for psql-splitter 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| psql_splitter-1.0.0.tar.gz | 9.0 kB | Without provenance | Details for psql_splitter-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| psql_splitter-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for psql_splitter-1.0.0-py3-none-any.whl |
Total release size: 16.7 kB
Release files / psql_splitter-1.0.0.tar.gz
| Download URL | psql_splitter-1.0.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac557ce4a51ac944253daccd608286a1c7bb31cea3073a7caf9965e0958aef67
|
|
BLAKE2b-256 checksum How to use checksums |
04ab0e9adfd760e2ca0b02c120a7748c3c7b79c7e7d8e742fb15f953090e15d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Release files / psql_splitter-1.0.0-py3-none-any.whl
| Download URL | psql_splitter-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cfac2e68fd0f72fbf75284a83308326d3af44afb2d036bd4edb7172bb74704d
|
|
BLAKE2b-256 checksum How to use checksums |
02340b22df1621fda86a8bb6f04ba0ea4586e1db832a3a43ba27178f48217b05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Security for psql-splitter 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.