Skip to main content

Deduplicate repeated sequences of lines in text streams and files

Project description

uniqseq

Stream-based deduplication for repeating sequences

Tests codecov Python 3.9+ Documentation License: MIT

What It Does

uniqseq identifies and removes repeated multi-record patterns from streaming data. Unlike traditional line-by-line deduplication tools, it detects when sequences of records repeat, where a record can be a line, a byte sequence, or any delimiter-separated unit.

Works with text streams (line-delimited, null-delimited, etc.) and binary streams (byte-delimited with any delimiter), processes data in a single pass, and maintains bounded memory usage.

Quick Example

# Input with repeated 3-line sequence
$ cat app.log
Starting process...
Loading config
Connecting to DB
Starting process...
Loading config
Connecting to DB
Done

# Remove duplicates (specify window size to match pattern length)
$ uniqseq --window-size 3 app.log
Starting process...
Loading config
Connecting to DB
Done

Key Features

  • Sequence detection - Identifies repeating multi-record patterns
  • Flexible delimiters - Text with any delimiter or byte streams
  • Streaming architecture - Single-pass processing with real-time output
  • Memory efficient - Bounded memory usage for unlimited input
  • Pattern filtering - Selectively deduplicate with regex patterns
  • Content transformation - Match on normalized content while preserving original output
  • Python API & CLI - Use as a command-line tool or import as a library
  • Sequence libraries - Save and reuse pattern libraries across sessions

Full Feature Documentation

Installation

# From source (PyPI coming soon)
pip install git+https://github.com/JeffreyUrban/uniqseq.git

# Development installation
git clone https://github.com/JeffreyUrban/uniqseq
cd uniqseq
pip install -e ".[dev]"

Requirements: Python 3.9+

Quick Start

Command Line

# Basic usage (deduplicate 10-line sequences by default)
uniqseq app.log > clean.log

# Adjust window size for your data
uniqseq --window-size 3 build.log    # 3-line patterns
uniqseq --window-size 5 errors.log   # 5-line patterns

# Stream processing
tail -f app.log | uniqseq --window-size 5

# Ignore timestamps when comparing
uniqseq --skip-chars 24 timestamped.log

# Only deduplicate ERROR lines
uniqseq --track "^ERROR" app.log

# See what was removed
uniqseq --annotate app.log

Python API

from uniqseq import UniqSeq

# Initialize with configuration
deduplicator = UniqSeq(
    window_size=3,
    skip_chars=0,
    max_history=100000
)

# Process stream
with open("app.log") as infile, open("clean.log", "w") as outfile:
    for line in infile:
        deduplicator.process_line(line.rstrip("\n"), outfile)
    deduplicator.flush(outfile)

Use Cases

  • Log processing - Clean repeated error traces, stack traces, debug output
  • Build systems - Deduplicate compiler warnings, test failures
  • Terminal sessions - Clean up verbose CLI output (from script command)
  • Monitoring & alerting - Reduce noise from repeated alert patterns
  • Data pipelines - Filter redundant multi-line records in ETL workflows
  • Binary analysis - Deduplicate repeated byte sequences in memory dumps, network captures

How It Works

uniqseq uses a sliding window with hash-based pattern detection:

  1. Buffering - Maintains a sliding window of N records
  2. Hashing - Computes a hash for each window position
  3. History tracking - Records which window patterns have been seen
  4. Sequence tracking - Tracks known multi-window sequences
  5. Matching - Compares current windows against history and known sequences
  6. Transformation - Optionally normalizes content for matching while preserving original data in output

Output is produced with minimal delay. When a window doesn't match any known pattern, the oldest buffered record is immediately emitted.

Documentation

Read the full documentation at uniqseq.readthedocs.io

Key sections:

  • Getting Started - Installation and quick start guide
  • Use Cases - Real-world examples across different domains
  • Guides - Window size selection, performance tips, common patterns
  • Reference - Complete CLI and Python API documentation

Development

# Clone repository
git clone https://github.com/JeffreyUrban/uniqseq.git
cd uniqseq

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=uniqseq --cov-report=html

Performance

  • Time complexity: O(n) - linear with input size
  • Space complexity: O(h + u×w) where h=history depth, u=known sequences, w=window size
  • Throughput: Approximately constant records per second
  • Memory: Bounded by configurable history depth

License

MIT License - See LICENSE file for details

Author

Jeffrey Urban


Star on GitHub | Report Issues

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

uniqseq-0.1.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

uniqseq-0.1.0-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file uniqseq-0.1.0.tar.gz.

File metadata

  • Download URL: uniqseq-0.1.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for uniqseq-0.1.0.tar.gz
Algorithm Hash digest
SHA256 00faf6590fa7de3498d3d7411ea0263fb0f69f3724d4ea31ea9a772318d375c8
MD5 374311aa15b7cc2c9145b919c3dd68d7
BLAKE2b-256 b80cf15f757e13bee6313da723b78866dd82323181a154a1ace3526dcdb5df39

See more details on using hashes here.

Provenance

The following attestation bundles were made for uniqseq-0.1.0.tar.gz:

Publisher: release.yml on JeffreyUrban/uniqseq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file uniqseq-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: uniqseq-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for uniqseq-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6928de1633aafb2b7111f703909eceb073de757510aa850e5d7ed1979f17341
MD5 423854599e2fd9e985467e014a3785e8
BLAKE2b-256 20c58b72e8cf23e2f1ceaa7c93f05845185da0b1555e731e6f865713c0c6840d

See more details on using hashes here.

Provenance

The following attestation bundles were made for uniqseq-0.1.0-py3-none-any.whl:

Publisher: release.yml on JeffreyUrban/uniqseq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page