Python library for number classification — 2140+ named number types, zero dependencies
Project description
numclassify
Given a number, what is it?
Most number-theory libraries — labmath, eulerlib, pyntlib — compute things: factor integers, find GCDs, generate primes. numclassify solves a different problem. Hand it a number and it tells you every named mathematical type that number belongs to, across 2140+ categories, with zero external dependencies.
Why I built this
I was doing number programs in school (Armstrong numbers, perfect numbers, that kind of thing) and went looking for a Python package I could just import instead of rewriting the same checks every time. I couldn't find one. Every library I found computed things, factors, GCDs, primes, but none of them actually classified a number into the type it was.
Then I realized why: schools include these programs in the syllabus to teach students Python and basic mathematical logic, not so students can look up which number is which. The exercise is the point. So a library that just answers "is this Armstrong" defeats the purpose schools have for assigning it in the first place.
That's why why() and the explain functions exist. Instead of just returning
True or False, numclassify shows the actual math, the same steps you'd write
out by hand. The goal isn't to do the homework for you. It's to be the thing
you check your own work against, or use to explore beyond what one assignment
asks for.
153 → Armstrong, Harshad, Triangular, Abundant, ...
1729 → Taxicab (Hardy-Ramanujan), Carmichael, Harshad, ...
28 → Perfect, Triangular, Hexagonal, Semiprime, ...
Try it in your browser: numclassify Playground
Installation
pip install numclassify
Python 3.8+ required. No external dependencies.
Quick Start
import numclassify as nc
# Boolean checks
nc.is_prime(17) # True
nc.is_perfect(28) # True
# Classify a single number
nc.classify(1729)
# {
# 'number': 1729,
# 'score': 22, # total true properties (incl. figurate)
# 'notable_score': 18, # score excluding polygonal figurate noise
# 'true_properties': ['Taxicab', 'Carmichael', ...],
# 'categories': {'primes': [...], 'sequences': [...], ...}
# }
# Batch classify
nc.classify_batch([6, 28, 496])
# Find numbers in a range with a given property
nc.find_by_property(start=1, end=1000, Perfect=True)
# [6, 28, 496]
# Stream over large ranges without loading everything into memory
for result in nc.stream(1, 1_000_000, min_score=20):
print(result)
# Stream only numbers with a specific property
for result in nc.stream(1, 10_000, has_property="prime"):
print(result)
# All true properties of a number (returns a dict of True properties)
nc.get_true_properties(1729)
# Pretty-print a formatted table
nc.print_properties(153)
# ┌─────────────────────────────────────────┐
# │ Properties of 153 │
# ├─────────────────────────────────────────┤
# │ armstrong ✓ │
# │ harshad ✓ │
# │ triangular ✓ │
# │ ... │
# └─────────────────────────────────────────┘
CLI
# Classify a number
numclassify check 1729
# JSON output for piping
numclassify check 153 --json
# Find numbers of a type
numclassify find armstrong --limit 10
# Filter a range
numclassify range 1 20 --filter prime
# Compare two numbers
numclassify compare 6 28
# List all types in a category
numclassify list --category primes
# Get info and OEIS reference for a type
numclassify info armstrong
Number Categories
| Category | Count | Examples |
|---|---|---|
| Polygonal figurate | ~1003 | Triangular, Square, Pentagonal, Chiliagonal |
| Centered polygonal | ~998 | Centered Triangular, Centered Hexagonal |
| Prime families | 40 | Twin, Mersenne, Sophie Germain, Wilson, Safe |
| Digital invariants | 13 | Armstrong, Spy, Harshad, Disarium, Happy, Neon |
| Divisor-based | 27 | Perfect, Abundant, Weird, Amicable, Practical |
| Sequences | 16 | Fibonacci, Lucas, Catalan, Bell, Padovan |
| Powers | 13 | Perfect Square, Taxicab, Sum of Two Squares |
| Number theory | 14 | Evil, Carmichael, Keith, Autobiographical |
| Combinatorial | 10 | Factorial, Primorial, Subfactorial |
| Recreational | 6 | Kaprekar, Automorphic, Palindrome |
| Exam types | 8 | Armstrong, Strong, Sunny, Buzz, Magic, Unique |
| Total | 2140+ |
Custom Types
The @register decorator lets you add your own number types. Once registered, the type appears everywhere — classify(), find_by_property(), the CLI, all of it.
from numclassify import register
@register(name="my_type", category="custom")
def is_my_type(n: int) -> bool:
return n > 0 and n % 7 == 0 and str(n)[0] == "4"
import numclassify as nc
nc.is_my_type(42) # True
nc.get_true_properties(42) # [..., 'my_type', ...]
See examples/ for runnable scripts covering all major features.
API Reference
| Function | Description |
|---|---|
classify(n) |
Returns {number, score, notable_score, true_properties, categories} |
classify_batch(numbers) |
Classify a list; returns list of dicts |
random_number(max_n) |
Classify a randomly selected number |
find_by_property(start, end, **filters) |
Numbers in range matching property filters |
stream(start, end, min_score, has_property) |
Generator — memory-safe range classification |
get_all_properties(n) |
Dict of every type mapped to True/False |
get_true_properties(n) |
List of True property names only |
print_properties(n) |
Pretty-print property table to stdout |
count_properties(n) |
Count of True properties |
most_special_in_range(lo, hi, verbose) |
Number in range with the most True properties |
find_in_range(fn, lo, hi) |
Numbers where callable fn returns True |
find_any_in_range(predicates, lo, hi) |
Integers in range satisfying at least one predicate |
find_all_in_range(predicates, lo, hi) |
Integers in range satisfying all predicates |
register |
Decorator to add custom number types |
is_prime(n) |
Convenience boolean |
is_armstrong(n) |
Convenience boolean |
is_perfect(n) |
Convenience boolean |
Full docs: aratrikghosh2011-tech.github.io/numclassify
License
MIT © 2026 Aratrik Ghosh
Project details
Release history Release notifications | RSS feed
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 numclassify-0.5.0.tar.gz.
File metadata
- Download URL: numclassify-0.5.0.tar.gz
- Upload date:
- Size: 78.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
041d0068bb856ee367f10031cdbe53bddcdba9ec186c179e4ddedef9e9894391
|
|
| MD5 |
fe0c44e8fdf0979a789e3e4f4f1f39d1
|
|
| BLAKE2b-256 |
50c08cb7ba78702330931b18373f7c8a1ba44e7c538e997d75a6e00270eb5f11
|
Provenance
The following attestation bundles were made for numclassify-0.5.0.tar.gz:
Publisher:
publish.yml on aratrikghosh2011-tech/numclassify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numclassify-0.5.0.tar.gz -
Subject digest:
041d0068bb856ee367f10031cdbe53bddcdba9ec186c179e4ddedef9e9894391 - Sigstore transparency entry: 1873187560
- Sigstore integration time:
-
Permalink:
aratrikghosh2011-tech/numclassify@2f51c98b31d3cbb338defa719043097ac0beb969 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/aratrikghosh2011-tech
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2f51c98b31d3cbb338defa719043097ac0beb969 -
Trigger Event:
push
-
Statement type:
File details
Details for the file numclassify-0.5.0-py3-none-any.whl.
File metadata
- Download URL: numclassify-0.5.0-py3-none-any.whl
- Upload date:
- Size: 56.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9693250dc0e5e5a72762d45bc37e3fb99a4730bbd337b64a98b0b129a79bc462
|
|
| MD5 |
4a72c8099b270b8468b4f02b08c0f697
|
|
| BLAKE2b-256 |
ad6d370ac9133e43001ecf10184ec3e71a0406f92c323010775a1a1b1bd92400
|
Provenance
The following attestation bundles were made for numclassify-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on aratrikghosh2011-tech/numclassify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numclassify-0.5.0-py3-none-any.whl -
Subject digest:
9693250dc0e5e5a72762d45bc37e3fb99a4730bbd337b64a98b0b129a79bc462 - Sigstore transparency entry: 1873187709
- Sigstore integration time:
-
Permalink:
aratrikghosh2011-tech/numclassify@2f51c98b31d3cbb338defa719043097ac0beb969 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/aratrikghosh2011-tech
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2f51c98b31d3cbb338defa719043097ac0beb969 -
Trigger Event:
push
-
Statement type: