Skip to main content

Count interesting number patterns in text files

Project description

numscan

numscan is a lightweight Python package that scans large text files for interesting number patterns — such as Fibonacci numbers, prime numbers, perfect squares, and more.

It’s designed for fast processing of files with mixed content (letters, symbols, digits), supports cross-line matching, and is fully extensible.

Features

  • Count appearances of numeric patterns in large files
  • Works across lines and inside mixed strings (e.g., abc123xyz)
  • Built-in support for:
    • Fibonacci numbers
    • Prime numbers
    • Square numbers
    • Pop culture numbers (e.g., 42, 1337)
    • All integers
  • Easy to extend with custom pattern counters
  • Python 3.9+ compatible

Installation

Install directly from PyPI:

pip install numscan

Or from GitHub (development version):

pip install git+https://github.com/ChristianRabenstein/numscan.git

Basic Usage

1. Count Fibonacci numbers in a file

from numscan import FibonacciCounter

counter = FibonacciCounter("example.txt")
print(counter.counts)

2. Count prime numbers

from numscan import PrimeCounter

prime_counter = PrimeCounter("example.txt")
print(prime_counter.counts)

3. Show top matches in a formatted way

def print_top_counts(counter, title, top_n=5):
    print(f"Top {top_n} matches for {title}:
")
    for number, count in sorted(counter.counts.items(), key=lambda x: x[1], reverse=True)[:top_n]:
        print(f"{number}: {count}")

fib_counter = FibonacciCounter("example.txt")
print_top_counts(fib_counter, "Fibonacci Numbers")

Example Output

Top 5 matches for Fibonacci Numbers:

1: 1582
0: 891
2: 474
3: 211
5: 102

Custom Pattern Example

Create your own number matcher by subclassing NumberCounter:

from numscan import NumberCounter

class MyLuckyNumbers(NumberCounter):
    def generate_numbers(self):
        return [7, 13, 21, 42]

lucky = MyLuckyNumbers("example.txt")
print(lucky.counts)

All Available Counters

Class Description
DatePatternCounter It supports multiple formats and checks all dates in a specified date range.
FibonacciCounter Matches Fibonacci numbers up to 1000
IntegerCounter Matches all integer numbers
PopCultureCounter Matches 42, 1337, 666, and more
PrimeCounter Matches prime numbers up to 1000
SquareCounter Matches perfect square numbers

Project Structure (Package Layout)

numscan/
│
├── base.py           # Base class: NumberCounter
├── date.py           # DatePatternCounter
├── fibonacci.py      # FibonacciCounter
├── prime.py          # PrimeCounter
├── squares.py        # SquareCounter
├── popculture.py     # PopCultureCounter
├── all.py            # IntegerCounter
├── __init__.py       # Unified exports

🧾 License

MIT License
© Christian Rabenstein — rabenstein.at

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

numscan-0.1.6.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

numscan-0.1.6-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file numscan-0.1.6.tar.gz.

File metadata

  • Download URL: numscan-0.1.6.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for numscan-0.1.6.tar.gz
Algorithm Hash digest
SHA256 044487d86bc84a9b7ad1a8f8b4cc7644e5caa013a3bbcef31b7ec7d71c81ab43
MD5 9dc935bdb9798294c8277a5b291f21f4
BLAKE2b-256 b7ab0649b4e9e9413cb08d76fe2bf92e795abeb389e37e19b7dbf853054ca26e

See more details on using hashes here.

File details

Details for the file numscan-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: numscan-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for numscan-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 088d59823ef60191115bac203a9e3bcf8a082956be51087bad4d8ab6c100fa7f
MD5 af14026afc9fb57a8f910f71e58e4eb7
BLAKE2b-256 9ba1b07df120938195a3d7c22308f5368ae549c5f15cfb6839cfe51e3cee49dd

See more details on using hashes here.

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