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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
044487d86bc84a9b7ad1a8f8b4cc7644e5caa013a3bbcef31b7ec7d71c81ab43
|
|
| MD5 |
9dc935bdb9798294c8277a5b291f21f4
|
|
| BLAKE2b-256 |
b7ab0649b4e9e9413cb08d76fe2bf92e795abeb389e37e19b7dbf853054ca26e
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
088d59823ef60191115bac203a9e3bcf8a082956be51087bad4d8ab6c100fa7f
|
|
| MD5 |
af14026afc9fb57a8f910f71e58e4eb7
|
|
| BLAKE2b-256 |
9ba1b07df120938195a3d7c22308f5368ae549c5f15cfb6839cfe51e3cee49dd
|