lookprime
lookprime is a high-performance prime number library for Python built around a memory-mapped, odd-only, bitset sieve.
It is designed for: - extremely fast primality tests - fast prime counting and enumeration - repeated queries across processes - large limits with minimal RAM overhead - CLI benchmarking and inspection
The core idea:
👉 build a prime sieve once, store it on disk, then reuse it via
mmap with near-zero startup cost.
Features
Core performance
- Odd-only sieve (½ the memory of full sieve)
- Bitset representation (1 bit per odd number)
- Memory-mapped cache (
mmap) for zero-copy sharing int.from_bytes(...).bit_count()for fast counting- Auto-growing cache when needed
- Safe for multi-process use (read-only)
Python API
isprime(n)isprime_many(iterable)primerange(a, b)randprime(a, b)primepi(n)prime(n)(nth prime, 1-indexed)prevprime(n)nextprime(n)primes(n)(firstnprimes)primes_up_to(n)factorint(n)cache_info()clear_cache()
CLI
lookprime infolookprime buildlookprime benchmarklookprime isprime <n>lookprime factor <n>lookprime clear-cache
Installation
pip install lookprime
Python ≥ 3.9 required.
Quick Start (Python)
import lookprime
lookprime.isprime(97) # True
lookprime.primepi(1_000_000) # 78498
lookprime.primes_up_to(50) # [2, 3, 5, 7, 11, ...]
lookprime.factorint(123456) # {2: 6, 3: 1, 643: 1}
Bulk checks:
lookprime.isprime_many([2, 3, 4, 5, 10**9 + 7])
How the Cache Works
-
Sieve files are stored in a platform-appropriate cache directory:
- Linux:
~/.cache/lookprime - macOS:
~/Library/Caches/lookprime - Windows:
%LOCALAPPDATA%\lookprime\Cache
- Linux:
-
Each sieve is stored as:
lookprime_mask_<limit>.lpm -
Files are memory-mapped (
mmap) and shared across processes -
Rebuilding happens only if needed
To inspect cache state:
lookprime.cache_info()
To delete all cached sieves:
lookprime.clear_cache()
or from CLI:
lookprime clear-cache
CLI Usage
Show system and cache info
lookprime info
Build a sieve explicitly
lookprime build --limit 100000000
Benchmark lookup speed
lookprime benchmark
Options:
lookprime benchmark \
--limit 100000000 \
--duration 1.0 \
--iterations 25 \
--chunk 65536
Environment override:
export LOOKPRIME_CHUNK=65536
lookprime benchmark
Primality from CLI
lookprime isprime 104729
Factor integers from CLI
lookprime factor 123456
Performance Notes
isprime(n)is O(1) after cache loadprimepi(n)uses bitset population countprime(n)andprimes(n)use fast bit scanning- Cache memory is shared between processes
- No Python objects are created per lookup
Threading & Multiprocessing
- The sieve is read-only
- Safe to open in multiple processes
- Each process memory-maps its own view
- No locks required
License
MIT License.
Metadata
Release files for lookprime 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lookprime-0.2.3.tar.gz | 16.6 kB | Without provenance | Details for lookprime-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lookprime-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for lookprime-0.2.3-py3-none-any.whl |
Total release size: 34.8 kB
Release files / lookprime-0.2.3.tar.gz
| Download URL | lookprime-0.2.3.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8800ee1849d1ca00ff7e9295e0ef48adeedf0e71e76e42cf49f6ed1ee550309
|
|
BLAKE2b-256 checksum How to use checksums |
643913db3ce2b75b0578d263f802ae5529113ea1833f94f122abec305912a4e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / lookprime-0.2.3-py3-none-any.whl
| Download URL | lookprime-0.2.3-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
577ba9c949e64b829100aec7733f413695aac1050d3d6b991c88c72b4637bd0d
|
|
BLAKE2b-256 checksum How to use checksums |
65dd202c85653cdc87b1b3c6083bd56f648faf174d329a1d117b8b522230c449
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for lookprime 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.