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
FibonacciCounter Matches Fibonacci numbers up to 1000
PrimeCounter Matches prime numbers up to 1000
SquareCounter Matches perfect square numbers
PopCultureCounter Matches 42, 1337, 666, and more
IntegerCounter Matches all integer numbers

Project Structure (Package Layout)

numscan/
│
├── base.py           # Base class: NumberCounter
├── 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.5.tar.gz (4.7 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.5-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: numscan-0.1.5.tar.gz
  • Upload date:
  • Size: 4.7 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.5.tar.gz
Algorithm Hash digest
SHA256 3dc18a250d92939f5d69c4da3632ed045be9384bc0425797299256e9b429e821
MD5 f4038e5c1978263923e3c262120d8bc0
BLAKE2b-256 3c2b330c7bb1e29e512d28923a977ed463a6be23bdfe8e2f37bfd89f9b5a67ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: numscan-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fe8edd23526cd96e30db3923592fc88b963187d946dca2c9c564870c1bba3e64
MD5 ee3766f56b87f1ef9273426212d620cf
BLAKE2b-256 9a8aa275546c1d68a920ff2be5bf932b75acda9226530731f97f93bfd52bff65

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