Skip to main content

The most comprehensive Python library for number classification - 3000+ number types

Project description

numclassify

PyPI version Downloads Python Tests License

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 3000+ categories, with zero external dependencies.

153   →  Armstrong, Harshad, Triangular, Abundant, ...
1729  →  Taxicab (Hardy-Ramanujan), Carmichael, Zeisel, ...
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 — returns number, true properties, and a score
nc.classify(1729)
# {'number': 1729, 'true_properties': ['Taxicab', 'Carmichael', ...], 'score': 22}

# 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):
    if result['score'] > 30:
        print(result)

# All true properties of a number
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 ~998 Triangular, Square, Pentagonal, Chiliagonal
Centered polygonal ~998 Centered Triangular, Centered Hexagonal
Prime families 41 Twin, Mersenne, Sophie Germain, Wilson, Safe
Digital invariants 10 Armstrong, Spy, Harshad, Disarium, Happy, Neon
Divisor-based 27 Perfect, Abundant, Weird, Amicable, Practical
Sequences 15 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 5 Kaprekar, Automorphic, Palindrome
Total 3000+

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, true_properties, score}
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) 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) Number in range with the most True properties
find_in_range(fn, lo, hi) Numbers where fn returns True
find_all_in_range(lo, hi) Dict mapping each number to its true properties
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numclassify-0.3.2.1.tar.gz (62.7 kB view details)

Uploaded Source

Built Distribution

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

numclassify-0.3.2.1-py3-none-any.whl (47.3 kB view details)

Uploaded Python 3

File details

Details for the file numclassify-0.3.2.1.tar.gz.

File metadata

  • Download URL: numclassify-0.3.2.1.tar.gz
  • Upload date:
  • Size: 62.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for numclassify-0.3.2.1.tar.gz
Algorithm Hash digest
SHA256 e43021553a3a04be887a284343b6e39b02417af50957a9087c1b5737a73369a0
MD5 b4b6377039335fb2e2d9c331f4b33e6a
BLAKE2b-256 8690ebb4aa4d9883faf0b4732d4e3392bbd841da630f420b0db8292e809269f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for numclassify-0.3.2.1.tar.gz:

Publisher: publish.yml on aratrikghosh2011-tech/numclassify

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

File details

Details for the file numclassify-0.3.2.1-py3-none-any.whl.

File metadata

  • Download URL: numclassify-0.3.2.1-py3-none-any.whl
  • Upload date:
  • Size: 47.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for numclassify-0.3.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a79e366afae5f2b0feb99a4869788ca81a4542f4f725f675f4b137af2ce7861c
MD5 3821f953f3ef7b47bbd4c980869898ea
BLAKE2b-256 7ce67a8bb3a45cb7946cb1506a5d53fc99765ab20b0b852e170d17bb295bb270

See more details on using hashes here.

Provenance

The following attestation bundles were made for numclassify-0.3.2.1-py3-none-any.whl:

Publisher: publish.yml on aratrikghosh2011-tech/numclassify

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