Python client for Basepair
Python bindings for Basepair's API and command line interface (CLI).
Sentry & custom metrics (optional)
Install with Sentry support:
pip install basepair[sentry]
The library provides shared Sentry init and entity metric constants so consumer apps (Pinda, webapp, ivfapp, kmap) do not duplicate scrubbing, sampling, or metric naming.
Important: basepair-python does not read environment variables for Sentry or metrics. Each app loads its own config and passes explicit parameters.
Sentry init
from basepair.sentry import init_sentry
init_sentry(
dsn=os.environ.get("SENTRY_DSN"),
environment=os.environ["MODE"],
release=os.environ["VERSION"],
service="pinda-backend",
traces_sample_rate=float(os.environ["SENTRY_TRACES_SAMPLE_RATE"]),
profile_sample_rate=float(os.environ["SENTRY_PROFILE_SAMPLE_RATE"]),
project_name=os.environ.get("PROJECT_NAME"),
customer_app=os.environ.get("CUSTOMER_APP"),
debug=os.environ.get("SENTRY_DEBUG") == "true",
low_value_transactions=("/api/health", "/api/health/"),
)
- Empty
dsn→ no-op (safe for local dev). - Required when
dsnis set:environment,release,service,traces_sample_rate,profile_sample_rate. - Optional:
project_name,customer_app,debug,low_value_transactions,server_name,enable_logs,enable_metrics. enable_logs/enable_metricsare passed through tosentry_sdk.initonly when set. Omit them for SDK defaults (Sentry Logs off; custom metrics on).
Django apps can use request context helpers:
from basepair.sentry.django import SentryContextMiddleware, set_request_sentry_context
Entity metrics
Shared metric names and tags live in basepair.metrics:
from basepair.metrics import (
METRIC_ANALYSIS_BULK_START,
METRIC_ANALYSIS_TERMINAL,
Source,
Tag,
Outcome,
emit,
)
Analysis.bulk_start and Analysis.reanalyze emit create-side metrics when Sentry is initialized in the calling process (requires sentry-sdk>=2.44.0 for the metrics API). Pass metric_source in the webapp API client config:
Analysis({**settings.WEBAPP["api"], "metric_source": Source.PINDA})
Webapp should emit completion metrics using the same constants (e.g. METRIC_ANALYSIS_TERMINAL) when an analysis reaches a terminal state.
Spec: Confluence — Sentry Custom Metrics
Using MFA
Note: It is advisable to use MFA for increased security and best practices
After you have been added to the list of collaborators, you can verify if MFA has been activated for you by visiting collaboration page
How to build and push to pypi:
Automated publishing of distribution
In the testing stage of the changes, it is advisable to use Test PyPI. We already have github actions to publish on both Test PyPI and PyPI.
Manual way from local
python setup.py sdist bdist_wheel # This will create two files in a newly created dist directory, a source archive and a wheel:
twine upload dist/* # To upload it to Pypi
Uploading distributions to https://upload.pypi.org/legacy/
Enter your username:
Enter your password:
Note: username must be __token__ (not your pypi username)
password is the token. You may generate the token -> token creation page.
That is it!
Below is a successful execution sample:
Uploading distributions to https://upload.pypi.org/legacy/
Enter your username: __token__
Enter your password:
Uploading basepair-2.0.7-py3-none-any.whl
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 51.0/51.0 kB • 00:00 • 36.3 MB/s
Uploading basepair-2.0.7.tar.gz
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 37.4/37.4 kB • 00:00 • 47.2 MB/s
View at:
https://pypi.org/project/basepair/2.0.7/
Metadata
Release files for basepair 3.4.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| basepair-3.4.5.tar.gz | 81.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| basepair-3.4.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 193.0 kB
Release files / basepair-3.4.5.tar.gz
| Download URL | basepair-3.4.5.tar.gz |
|---|---|
| Size | 81.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebb60d035fed9a612a335e1e4c0253a3a184dd5df7f7a5d1921e9d6e936c3b13
|
|
BLAKE2b-256 checksum How to use checksums |
51a75a02e37de334184e342e1ee5f7e4144b734064442058a943ab7a22b0b4f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / basepair-3.4.5-py3-none-any.whl
| Download URL | basepair-3.4.5-py3-none-any.whl |
|---|---|
| Size | 111.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ab1b7da6828516414dbf74908b3b0e2642b0019728d955464ad609ac94367fe
|
|
BLAKE2b-256 checksum How to use checksums |
0f79e31cdcc2ed32360ce99a55a065896ed8d85e82eb6fc51ac44ede9ce7fbc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|