Look a number up in NumberDB and find out whether it is already known
Project description
numberdb
Look a number up in NumberDB and find out whether it is already known, and where else it appears.
$ pip install numberdb
>>> import numberdb
>>> for result in numberdb.search('pi'):
... print(result.exact_text, '--', result.table.title)
3.14159265358979323846264338327950288419716939937510582097494 -- Pi
3.14159265358979323846264338327950288419716939937510582097494 -- Complete elliptic integral ...
In SageMath
The same package, with one import line:
$ sage -pip install numberdb
sage: import numberdb.sage as numberdb
sage: numberdb.search('{n: pi^n for n in [1..5]}')[0].value
3.141592653589794?
Everything below that line reads exactly as it would in plain Python — there is
no mode to set and nothing to pass at each call. numberdb.sage re-exports the
whole package, so it can stand in for it wholesale.
It uses the SageMath you already have and installs nothing. There is no
numberdb[sage] extra, deliberately: inside a full SageMath it would install
passagemath over the top, and the passagemath-flint wheel writes 383 files
under sage/, 349 of which already exist there — including compiled
extensions. pip reports no conflict, because Sage's own files belong to no pip
distribution.
If you have no Sage and still want Sage objects, install passagemath into a fresh environment, never into an existing Sage.
Plain import numberdb never imports Sage at all, so it starts instantly; the
conversion is available per result as .sage() when you want it.
What you get back
search() returns a list of results, each carrying:
.value |
the number in plain Python (decoded on demand) |
.exact_text |
how the database writes it — the form to quote or paste back into a search |
.str_short |
a short form, comparable across results |
.table |
where it lives (.tid, .title, .url) |
.param |
which entry of that table it is |
.sage() |
the number as a Sage object |
.url() |
where to read about it |
.value is one of int, Fraction, RealInterval, ComplexInterval,
PAdic or Polynomial. A PAdic carries a Fraction — Q_p is not Z_p, so a
value of negative valuation such as 1/5 in Q_5 has no integer form — and its
precision is absolute: the ball is everything congruent to value modulo
prime ** precision, matching the O(p^k) in its string form. Exact values stay exact: integers are Python int (unbounded —
the database holds integers of over a thousand digits), rationals are
Fraction, and interval endpoints are exact Fractions rather than rounded
floats. Converting to float is your decision, never an accident of transport.
>>> result.value
RealInterval(884279719003555/281474976710656, 7074237752028441/2251799813685248)
>>> float(result.value) # the midpoint, explicitly lossy
3.141592653589793
The search itself may have something to say — that it was capped, or that part of the expression was rejected:
>>> results = numberdb.search('...')
>>> results.messages
['We only show the first 100 results.']
When the server is newer than the package
NumberDB will learn new kinds of number. An older package still returns every
result: values are decoded when you ask for them, so an unfamiliar one costs
you that value and nothing else, and its exact_text is there regardless.
>>> for result in numberdb.search('...'):
... if result.is_readable:
... use(result.value)
... else:
... print(result.exact_text) # still perfectly readable
results.unreadable lists them, and every exception the package raises derives
from numberdb.NumberDBError, so one except covers it.
Rate limits and API keys
Anonymous use is rate limited. A key raises the limit:
Keep it out of your worksheet — a shared notebook should not carry its author's key:
$ export NUMBERDB_API_KEY=...
or, if you must set it in code:
>>> numberdb.configure(api_key='...')
For more than one server or key in a process, use a client directly:
>>> client = numberdb.Client(api_key='...', base_url='http://localhost:8000/')
>>> numberdb.search('pi', client=client)
Exceeding the limit raises numberdb.RateLimited, which carries .retry_after
in seconds when the server supplies it.
Pointing it somewhere else
The default is https://numberdb.org. Override it for a development server, or
a private instance:
$ export NUMBERDB_URL=http://localhost:8000
>>> client = numberdb.Client(base_url='https://example.org/numberdb')
>>> numberdb.search('pi', client=client)
A trailing slash is optional — a base URL with a path prefix keeps it either way.
Other calls
>>> numberdb.table('T12') # a whole table, as stored
>>> numberdb.tag('Irrational') # the tables carrying a tag
Why a package and not a file to copy
The API sends JSON, and turning it into numbers has to happen somewhere. Doing
it by hand is how the previous example client came to call loads() on
server-supplied bytes — which executes whatever those bytes say, handing code
execution to anyone able to answer the request. In this package decoding is a
fixed table: a response can select one of seven decoders and nothing else.
Being a package also means it is versioned. When the wire format changes, that is a version bump and a clear error telling you to upgrade, rather than an exception in the middle of your session.
Licence
GPL-3.0-or-later, matching NumberDB.
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 numberdb-0.0.1.tar.gz.
File metadata
- Download URL: numberdb-0.0.1.tar.gz
- Upload date:
- Size: 44.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ef8e3d32dc78f8aa127fb921e3773478ca90ba7098883c5e74e00440c88c750
|
|
| MD5 |
213b4f27a50a47891c11aba70511b0d2
|
|
| BLAKE2b-256 |
2967b0da2ac88a61c4210e65692fb9e9d0ea8290316298ce6fe51622d931c301
|
Provenance
The following attestation bundles were made for numberdb-0.0.1.tar.gz:
Publisher:
publish-numberdb.yml on numberdb/numberdb-website
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numberdb-0.0.1.tar.gz -
Subject digest:
4ef8e3d32dc78f8aa127fb921e3773478ca90ba7098883c5e74e00440c88c750 - Sigstore transparency entry: 2329199537
- Sigstore integration time:
-
Permalink:
numberdb/numberdb-website@106619dc72f7e705eea7f7bcc826af6ee5c16c2c -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/numberdb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-numberdb.yml@106619dc72f7e705eea7f7bcc826af6ee5c16c2c -
Trigger Event:
release
-
Statement type:
File details
Details for the file numberdb-0.0.1-py3-none-any.whl.
File metadata
- Download URL: numberdb-0.0.1-py3-none-any.whl
- Upload date:
- Size: 35.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c65658c328c1fcd01439c540e48d6b19432cca7c35466a7c5af4d390df5945a
|
|
| MD5 |
d2221a9e092c39157bf627748adb8ce9
|
|
| BLAKE2b-256 |
0d898e976ee39fa7fedd38074fb428352cc40dab4577d8e3aa832532d65d4b8b
|
Provenance
The following attestation bundles were made for numberdb-0.0.1-py3-none-any.whl:
Publisher:
publish-numberdb.yml on numberdb/numberdb-website
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numberdb-0.0.1-py3-none-any.whl -
Subject digest:
8c65658c328c1fcd01439c540e48d6b19432cca7c35466a7c5af4d390df5945a - Sigstore transparency entry: 2329199608
- Sigstore integration time:
-
Permalink:
numberdb/numberdb-website@106619dc72f7e705eea7f7bcc826af6ee5c16c2c -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/numberdb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-numberdb.yml@106619dc72f7e705eea7f7bcc826af6ee5c16c2c -
Trigger Event:
release
-
Statement type: