Skip to main content

tns-mirror-client

Typed, read-only Python access to a tns-mirror database — a local mirror of the IAU Transient Name Server public objects catalogue.

Add the library, get results. No hand-written SQL, and no rate-limited API on your hot path.

$ pip install 'tns-mirror-client>=1,<2'
import os
from tns_mirror_client import TnsMirror

with TnsMirror(dsn=os.environ["TNS_RO_DSN"]) as tns:
    hit = tns.nearest(ra=203.1, dec=10.2, radius_arcsec=3.0)
    if hit:
        print(hit.name, hit.type, hit.redshift, f'{hit.separation_arcsec:.2f}"')

    obj = tns.by_name("AT2026abc")
    print(tns.count(), "objects mirrored")

You need a read-only DSN from whoever operates the mirror. This library never writes, and it carries no TNS credentials — those belong to the server.

Why not just write the SQL?

Because a cone search on a sphere has three edges that are easy to get wrong and fail silently:

  • The cosine must be clamped before acos, or an exact positional match — the most common case in a cross-match — raises a domain error.
  • Near a pole the RA bound stops meaning anything: two objects 177° apart in right ascension can be 0.2° apart on the sky.
  • At the 0/360 seam, ra BETWEEN 359.5 AND 0.5 matches nothing at all.

This library handles all three, and keeps the indexed bounding-box prefilter that makes the query fast. The geometry is tested by sampling the rim of the cone at every bearing and asserting the prefilter never excludes a point that is genuinely inside the radius.

API

Method Returns
nearest(ra, dec, radius_arcsec=3.0) TnsObject | None — closest match, ties broken on objid
search(ra, dec, radius_arcsec, limit=None) list[TnsObject] — everything in range, nearest first
by_name(name) TnsObject | None
by_objid(objid) TnsObject | None
by_names(names) dict[str, TnsObject] — many in one round trip
count() int
meta() MirrorMeta — schema version and freshness

TnsObject mirrors the schema columns exactly: objid, name, ra, dec, type, redshift, discoverydate, discoverymag, internal_names, reporting_group, source_snapshot, refreshed_at — plus separation_arcsec, populated only by cone queries.

Everything but objid, name, ra, dec, source_snapshot and refreshed_at is nullable, and a minimal TNS row is common. Do not assume type or redshift is populated; hit.is_classified says whether TNS has published a classification.

Check freshness before you trust it

A row count looks identical whether the mirror synced an hour ago or died three weeks ago:

meta = tns.meta()
if not meta.is_fresh(max_age_hours=26):
    raise RuntimeError(f"TNS mirror is stale: last sync {meta.age} ago")

Versioning

Client 1.x speaks schema v1. The major version tracks the contract, not the project milestone, so pin it:

tns-mirror-client>=1,<2

You are then insulated from additive schema changes — a new nullable column or a new index bumps the minor and never breaks a reader. A breaking change bumps both majors together and is announced in the changelog.

The client reads the mirror's published schema_version on connect and raises SchemaVersionError on a mismatch rather than returning quietly wrong answers. That check needs SELECT on tns_mirror_meta, which the mirror's print-grants output includes; pass check_schema_version=False to skip it.

Connections

TnsMirror(dsn=...) opens lazily and closes with the context manager or .close(). To reuse a connection you already manage — from a pool, say — pass it instead, and the client will not close what it did not open:

tns = TnsMirror(connection=my_conn)

If the mirror was deployed with a non-default TNS_SCHEMA/TNS_TABLE, pass schema= and table=.

The client sets its session read-only as defence in depth, so even a bug in this library cannot write through a privileged role.

Dependencies

One: psycopg. This gets embedded in other people's applications, so results are plain dataclasses rather than a validation framework.

Requires Python 3.11+.

Licence

MIT. The mirrored catalogue itself is not the mirror's to license — follow the TNS data-use terms and cite TNS as they require.

Download files

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

Source Distribution

tns_mirror_client-1.0.4.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

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

tns_mirror_client-1.0.4-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file tns_mirror_client-1.0.4.tar.gz.

File metadata

  • Download URL: tns_mirror_client-1.0.4.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tns_mirror_client-1.0.4.tar.gz
Algorithm Hash digest
SHA256 418f2b285c8469fd740195feac7fe738b5f14a13c393db26d1d3200990a591dd
MD5 4dacaae0a03edada6da368200cc72d13
BLAKE2b-256 83f9b8d3cbd38d5331dc9a70993c4e09b95630325a17a8ed8c7d1bf27ec831bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tns_mirror_client-1.0.4.tar.gz:

Publisher: release.yml on sarhatabaot/tns-mirror

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

File details

Details for the file tns_mirror_client-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for tns_mirror_client-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d0bd005aee78fa81d91b1dec2b85c132342e3d1fb698ca9838a7f72a5844ae1e
MD5 dcee58fc9f34d01bee94ee0e46e42c82
BLAKE2b-256 78b1b74410e83730c085c45da591fa8b05306de232a3d032ad59aaa288510416

See more details on using hashes here.

Provenance

The following attestation bundles were made for tns_mirror_client-1.0.4-py3-none-any.whl:

Publisher: release.yml on sarhatabaot/tns-mirror

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

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page