Metadata-Version: 2.4
Name: basepair
Version: 3.4.0
Summary: Python client for Basepair's API
Home-page: https://bitbucket.org/basepair/basepair
Download-URL: https://bitbucket.org/basepair/basepair/get/3.4.0.tar.gz
Author: Basepair
Author-email: info@basepairtech.com
Keywords: bioinformatics,ngs analysis,dna-seq,rna-seq,chip-seq,atac-seq
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: Free for non-commercial use
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: LICENSE.txt
Requires-Dist: boto3
Requires-Dist: future
Requires-Dist: requests
Requires-Dist: awscli
Requires-Dist: logbook
Requires-Dist: tabulate
Provides-Extra: sentry
Requires-Dist: sentry-sdk>=2.0.0; extra == "sentry"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: download-url
Dynamic: home-page
Dynamic: keywords
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: summary

Python client for Basepair
======================

Python bindings for Basepair's API and command line interface (CLI).

## Sentry & custom metrics (optional)

Install with Sentry support:

```bash
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

```python
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 `dsn` is set: `environment`, `release`, `service`, `traces_sample_rate`, `profile_sample_rate`.
- Optional: `project_name`, `customer_app`, `debug`, `low_value_transactions`, `server_name`.

Django apps can use request context helpers:

```python
from basepair.sentry.django import SentryContextMiddleware, set_request_sentry_context
```

### Entity metrics

Shared metric names and tags live in `basepair.metrics`:

```python
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. Pass `metric_source` in the webapp API client config:

```python
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](https://basepairtech.atlassian.net/wiki/spaces/BA/pages/342818817/Sentry+Custom+Metrics+-+Pinda+basepair-python+Webapp+Entities)

### 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](https://pypi.org/manage/project/basepair/collaboration/)

### 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](https://test.pypi.org/).
We already have github actions to publish on both Test PyPI and PyPI.
* [Publish Test Packages GitHub Action](https://github.com/basepair/basepair-python/actions/workflows/publish-test-package.yml)
* [Publish Production Package GitHub Action](https://github.com/basepair/basepair-python/actions/workflows/publish-package.yml)

#### Manual way from local
```BASH
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](https://pypi.org/manage/account/token/).

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/
```
