A Python package for Azure Genome.
Project description
azure-genome
A Python client library for the Azure Genome supply-chain service. The current release focuses on authenticated data ingestion — uploading entity, product, and relationship files and orchestrating graph builds.
Installation
pip install azure-genome
Requires Python 3.11 or later.
Quick start
1. Authenticate
Static bearer token — use when you already have a short-lived token (e.g. from CI or a test harness):
from azure_genome import StaticTokenCredential
credential = StaticTokenCredential(access_token="<your-bearer-token>")
Certificate-based — use GenomeCertificateCredential for production workloads that authenticate via a client certificate registered in Entra ID. The recommended approach is to store the certificate in Azure Key Vault and load it at runtime. Key Vault exposes the certificate bundle (certificate + private key) as a base64-encoded PFX through its Secrets API:
pip install azure-keyvault-secrets azure-identity
import base64
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
from cryptography.hazmat.primitives.serialization.pkcs12 import load_pkcs12
from azure_genome import GenomeCertificateCredential
# Fetch the certificate bundle from Key Vault
kv_credential = DefaultAzureCredential()
secret_client = SecretClient(
vault_url="https://<vault-name>.vault.azure.net",
credential=kv_credential,
)
secret = secret_client.get_secret("<certificate-name>")
pfx_bytes = base64.b64decode(secret.value)
# Parse the PFX to extract the private key and certificate
pkcs12 = load_pkcs12(pfx_bytes, password=None)
private_key = pkcs12.key
certificate = pkcs12.cert.certificate
credential = GenomeCertificateCredential(
tenant_id="<tenant-id>",
client_id="<client-id>",
scope="<scope>",
private_key=private_key,
certificate=certificate,
)
The certificate credential caches tokens in-memory and refreshes them automatically ~30 minutes before expiry.
2. Create a client
from azure_genome import GenomeClient
client = GenomeClient(
endpoint="https://<your-genome-service>.example.com",
credential=credential,
)
Note: Only HTTPS endpoints are accepted. The client will raise a
TransportErrorif a non-HTTPS endpoint is provided.
The root client exposes the following surface today:
| Attribute | Status | Purpose |
|---|---|---|
client.data |
Stable | Upload entity, product, and relationship files; trigger and monitor graph builds |
client.swagger |
Stable | Fetch the live OpenAPI specification from the configured endpoint |
client.query |
Preview / WIP | Read entities, products, and traverse the supply chain graph |
client.control |
Preview / WIP | Start and inspect background jobs |
client.deployment |
Preview / WIP | Manage workspaces |
The
query,control, anddeploymentsub-clients are under active development and their surfaces may change. This README only documents the stable data-ingestion flow.
3. Upload data
# Upload a full entity file (CSV or gzip)
response = client.data.upload_data(
data_type="entity",
file_path="entities.csv",
push_type="full", # or "delta"
)
print(response.requestId, response.status)
Supported data_type values:
entity,productentityaddressrel,entityflagrel,entityidentifierrelentityownsentityrel,entitysuppliedbyentityrelentitysellsproductrel,entitybuysproductrelproductcontainscomponentrel,producthasvariantrel,productflagrel
push_type accepts "full" (replace all records of this type) or "delta" (apply incremental changes). Files must end in .csv or .gz.
4. Track upload status
# Poll a single request
status = client.data.check_upload_status(response.requestId)
print(status.status, status.errorMessage)
# Or list every upload submitted to the service
all_uploads = client.data.list_uploads()
for upload in all_uploads.uploads or []:
print(upload.requestId, upload.dataType, upload.status)
5. Build the graph
After every file in a batch reports "Completed", trigger a graph build so the service incorporates the new data:
import time
build = client.data.build_graph()
print(build.buildId, build.status)
# Poll until terminal
while True:
result = client.data.check_build_status(build.buildId)
if result.status in ("Completed", "Failed"):
break
time.sleep(5)
print(result.status, result.errorMessage)
List previous builds:
for b in (client.data.list_builds().builds or []):
print(b.buildId, b.status, b.modifiedOn)
6. Inspect the service contract (optional)
spec = client.swagger # returns the parsed OpenAPI JSON dict
print(spec["info"]["title"], spec["info"]["version"])
Error handling
All exceptions inherit from GenomeError:
| Exception | Raised when |
|---|---|
AuthenticationError |
Token or certificate details are missing or invalid |
TransportError |
An HTTP request cannot be prepared or sent (includes non-HTTPS endpoints and non-2xx responses) |
DataUploadError |
An upload argument is invalid or the upload fails |
GenomeError |
Base class — catch this to handle any service-side failure |
from azure_genome import GenomeError
from azure_genome.utils.exceptions import DataUploadError, TransportError
try:
response = client.data.upload_data(
data_type="entity",
file_path="entities.csv",
)
except DataUploadError as exc:
print(f"Upload rejected: {exc}")
except TransportError as exc:
print(f"Network or HTTP failure: {exc}")
except GenomeError as exc:
print(f"Service error: {exc}")
Logging
The library logs request lifecycle events to the azure_genome logger hierarchy at INFO. Enable it like any standard logger:
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger("azure_genome").setLevel(logging.INFO)
Compatibility
- Python: 3.11, 3.12, 3.13, 3.14
- Transport: HTTPS only — bearer tokens are never sent over unencrypted connections
License
See LICENSE for details.
Project details
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 azure_genome-0.1.4.tar.gz.
File metadata
- Download URL: azure_genome-0.1.4.tar.gz
- Upload date:
- Size: 3.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2774251a6182afa42d79f78efdaac2032037d4880592e04dce4a23e8a68e8fe6
|
|
| MD5 |
d287a41f5742be49852e30b0739b4ea1
|
|
| BLAKE2b-256 |
48dcad99dfe999182d1e55e4213afedf8e16ed60ba8782d829d2f9d7886692d9
|
File details
Details for the file azure_genome-0.1.4-py3-none-any.whl.
File metadata
- Download URL: azure_genome-0.1.4-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4a23eacdbf144c554e7c746620b0be4beb3e0e003089e16910be75d61b2fd9e
|
|
| MD5 |
efccae634f66d7634e856ccc6b7dbb7b
|
|
| BLAKE2b-256 |
a8963099491222794d8c5f035bb498d6550b1964272b4d7634d2b5bfbcd6930b
|