Skip to main content

📂 splitxfiles

PyPI Python Versions License Downloads

A simple and lightweight Python library and Command Line Interface (CLI) for splitting files into smaller parts based on line count (text files) or file size (any file).

Ideal for processing log files, datasets, backups, wordlists, and other large files.


✨ Features

  • 📄 Split UTF-8 text files by line count
  • 📦 Split any file by file size
  • 🐍 Easy-to-use Python API
  • 💻 Command Line Interface (CLI)
  • 📁 Automatically creates output directories
  • 📊 Optional progress output
  • ✅ Cross-platform (Windows, Linux, macOS)

📦 Installation

Install from PyPI

pip install splitxfiles

Install from Source

git clone https://github.com/Lutfifakee-Project/splitxfiles.git

cd splitxfiles

pip install -e .

🖥 Requirements

  • Python 3.6 or later
  • Windows
  • Linux
  • macOS

🚀 Python Usage

Split Text File by Line Count

from splitxfiles import split_by_lines

split_by_lines(
    input_path="data.txt",
    output_path="output",
    lines_per_file=100
)

Split File by Size

from splitxfiles import split_by_size

split_by_size(
    input_path="archive.bin",
    output_path="output",
    size_bytes=1024 * 1024  # 1 MB
)

💻 Command Line Usage

Split by Line Count

splitxfiles input.txt -o output -l 100

Split by File Size

splitxfiles input.bin -o output -s 1048576

Quiet Mode

splitxfiles input.txt -l 100 -q

Display Help

splitxfiles --help

⚙ CLI Options

Option Description
-l, --lines Split file by line count
-s, --size Split file by size (bytes)
-o, --output Output directory (default: split_output)
-q, --quiet Disable progress output
-h, --help Show help message

📂 Output

Example directory:

output/

├── data_part_1.txt
├── data_part_2.txt
├── data_part_3.txt
└── data_part_4.txt

Output files are automatically named using the following format:

<original_filename>_part_<number>.<extension>

Example:

log_part_1.txt
log_part_2.txt
log_part_3.txt

📸 Example Output

📄 Splitting 1500 lines into 3 files...
📁 Output folder: output
--------------------------------------------------
✅ [1/3] data_part_1.txt (500 lines)
✅ [2/3] data_part_2.txt (500 lines)
✅ [3/3] data_part_3.txt (500 lines)
--------------------------------------------------
✅ Done! 3 files created successfully.

Note

The exact output may vary depending on the verbose option and future versions.


📚 API Reference

split_by_lines()

Split a UTF-8 text file into multiple smaller files based on the number of lines.

split_by_lines(
    input_path,
    output_path,
    lines_per_file,
    verbose=True
)

Parameters

Parameter Type Description
input_path str Path to the input text file
output_path str Output directory
lines_per_file int Maximum number of lines per output file
verbose bool Show progress information (default: True)

Returns

Type Description
bool Returns True if the operation succeeds, otherwise False.

split_by_size()

Split any file into multiple smaller files based on file size.

split_by_size(
    input_path,
    output_path,
    size_bytes,
    verbose=True
)

Parameters

Parameter Type Description
input_path str Path to the input file
output_path str Output directory
size_bytes int Maximum size of each output file (bytes)
verbose bool Show progress information (default: True)

Returns

Type Description
bool Returns True if the operation succeeds, otherwise False.

⚠ Error Handling

The functions return False when:

  • The input file does not exist.
  • The input file is empty.
  • The specified line count is less than or equal to zero.
  • The specified file size is less than or equal to zero.
  • An unexpected exception occurs during processing.

🧪 Running Tests

Run all unit tests:

python -m unittest tests/test_split.py -v

📁 Project Structure

splitxfiles/

├── src/
│   └── splitxfiles/
│       ├── __init__.py
│       └── cli.py
│
├── tests/
│   └── test_split.py
│
├── README.md
├── LICENSE
├── pyproject.toml
├── setup.py
└── .gitignore

🚧 Future Plans

  • Merge split files
  • Progress bar
  • Multi-threaded processing
  • Compression support
  • Progress percentage display
  • Improved error reporting

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

splitxfiles-0.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

splitxfiles-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file splitxfiles-0.1.1.tar.gz.

File metadata

  • Download URL: splitxfiles-0.1.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for splitxfiles-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5067bf766abbbca617db679a1511d7735b8007e2a426aee366582d5b6ae8da85
MD5 1bbad52a1c99dc1e0a42ab7f42db1c80
BLAKE2b-256 11003379e16d903d35d11628dbc39c67b96cf04c634df0030d7cdd1eb1f9fa41

See more details on using hashes here.

File details

Details for the file splitxfiles-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: splitxfiles-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for splitxfiles-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f30ff990538e0887c955464ce2e5ad92bf6cfc1955b8461641dd4be23c08a99
MD5 c25946132d910c69c5b1d58465527d6f
BLAKE2b-256 716cfdaf1c313cea2a842a73a0244247c7e93a512de452a6e1e0a3e395253ea2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page