Skip to main content

A Python package for Azure Genome.

Project description

azure-genome

A Python client library for the Azure Genome supply-chain service. Provides authentication, data ingestion, and graph query operations through a single root client.

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,
)

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 TransportError if a non-HTTPS endpoint is provided.

The root client exposes four sub-clients as attributes:

Attribute Purpose
client.data Upload entity and relationship CSV/GZ files
client.query Read entities, products, and traverse the supply chain graph
client.control Start and inspect background jobs
client.deployment Manage workspaces (preview)

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)

Supported data_type values:

  • entity, product
  • entityaddressrel, entityflagrel, entityidentifierrel
  • entityownsentityrel, entitysuppliedbyentityrel
  • entitysellsproductrel, entitybuysproductrel
  • productcontainscomponentrel, producthasvariantrel, productflagrel

4. Query the supply chain graph

Get a single entity or product:

entity = client.query.get_entity("3fa85f64-5717-4562-b3fc-2c963f66afa6")
print(entity.name)

product = client.query.get_product("3fa85f64-5717-4562-b3fc-2c963f66afa6")
print(product.name)

List entities with optional filters:

records = client.query.list_entities(filters={"source": "customer"})
for entity in records.items:
    print(entity.id, entity.name)

Traverse the supply chain graph:

graph = client.query.traverse_graph(
    start_entity_key="3fa85f64-5717-4562-b3fc-2c963f66afa6",
    upstream_depth=2,
    downstream_depth=3,
)

N-tier search:

results = client.query.search_n_tier(
    entity_key="3fa85f64-5717-4562-b3fc-2c963f66afa6"
)

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
DataUploadError A data upload operation fails
QueryError A query argument is invalid or the resource is not found
from azure_genome import GenomeError
from azure_genome.utils.exceptions import QueryError

try:
    entity = client.query.get_entity(entity_key)
except QueryError as exc:
    print(f"Query failed: {exc}")
except GenomeError as exc:
    print(f"Service error: {exc}")

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

azure_genome-0.1.1.tar.gz (68.5 kB view details)

Uploaded Source

Built Distribution

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

azure_genome-0.1.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file azure_genome-0.1.1.tar.gz.

File metadata

  • Download URL: azure_genome-0.1.1.tar.gz
  • Upload date:
  • Size: 68.5 kB
  • 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

Hashes for azure_genome-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ef34d9d61da5941614d62585c1b2d7b7a95dd8c40e1b82884e13756bbd03b270
MD5 638e187c3573637c0451f40d3cb138bf
BLAKE2b-256 4909ee40455b29f9972640f2624fa33c2d41af2288ce65044c43de0d2e0cdb05

See more details on using hashes here.

File details

Details for the file azure_genome-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: azure_genome-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 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

Hashes for azure_genome-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 77311f36615d46bf1f20b0f8837cc5943acaf442a79b48238b69432e286d1afb
MD5 4120106faedadec2afe2e0498b2bb551
BLAKE2b-256 849e9b6df636d88b992f153d10413d9bf713bbd1ea8c275d7d73092f1d69592b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page