interopdb 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: interopdb
3
+ Version: 0.1.0
4
+ Summary: Python client for the Interop DB Registry API
5
+ Requires-Python: >=3.9
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: httpx>=0.24
8
+ Requires-Dist: click>=8.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=7.0; extra == "dev"
11
+ Requires-Dist: pytest-httpx>=0.21; extra == "dev"
12
+
13
+ # interopdb
14
+
15
+ Python client and CLI for the [Interop DB Registry](https://interopdb-staging-f-ca.salmonpebble-cac1724c.northeurope.azurecontainerapps.io/) API.
16
+
17
+ Interop DB is a federated registry that assigns unified identifiers to genes and strains across multiple biological databases, enabling cross-database queries with a single search. It integrates data from:
18
+
19
+ - **ALEdb** -- Adaptive Laboratory Evolution Database
20
+ - **BiGGr** -- Knowledgebase of genome-scale metabolic network reconstructions
21
+ - **PanKB** -- Pangenome Knowledge Base (genes, strains, pangenomics)
22
+ - **PMkbase** -- Phenotype MicroArray Knowledge Base (strains, phenotypes)
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install interopdb
28
+ ```
29
+
30
+ ## Python API
31
+
32
+ ```python
33
+ from interopdb import InteropClient
34
+
35
+ client = InteropClient()
36
+
37
+ # Query a gene
38
+ result = client.get_gene("rpoB")
39
+ print(result["uid"], result["attributes"])
40
+
41
+ # Query a strain
42
+ result = client.get_strain("511145")
43
+
44
+ # Query a gene-strain pair
45
+ result = client.get_pair("rpoB", "511145")
46
+ for source in result["sources"]:
47
+ print(source["source"], source["data"])
48
+
49
+ # Save result to JSON
50
+ client.save_json(result, "output.json")
51
+ ```
52
+
53
+ ## CLI
54
+
55
+ ```bash
56
+ # Query entities
57
+ interopdb gene rpoB
58
+ interopdb strain 511145
59
+
60
+ # Query a gene-strain pair
61
+ interopdb pair rpoB 511145
62
+
63
+ # Save to file
64
+ interopdb gene rpoB -o result.json
65
+ ```
@@ -0,0 +1,53 @@
1
+ # interopdb
2
+
3
+ Python client and CLI for the [Interop DB Registry](https://interopdb-staging-f-ca.salmonpebble-cac1724c.northeurope.azurecontainerapps.io/) API.
4
+
5
+ Interop DB is a federated registry that assigns unified identifiers to genes and strains across multiple biological databases, enabling cross-database queries with a single search. It integrates data from:
6
+
7
+ - **ALEdb** -- Adaptive Laboratory Evolution Database
8
+ - **BiGGr** -- Knowledgebase of genome-scale metabolic network reconstructions
9
+ - **PanKB** -- Pangenome Knowledge Base (genes, strains, pangenomics)
10
+ - **PMkbase** -- Phenotype MicroArray Knowledge Base (strains, phenotypes)
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pip install interopdb
16
+ ```
17
+
18
+ ## Python API
19
+
20
+ ```python
21
+ from interopdb import InteropClient
22
+
23
+ client = InteropClient()
24
+
25
+ # Query a gene
26
+ result = client.get_gene("rpoB")
27
+ print(result["uid"], result["attributes"])
28
+
29
+ # Query a strain
30
+ result = client.get_strain("511145")
31
+
32
+ # Query a gene-strain pair
33
+ result = client.get_pair("rpoB", "511145")
34
+ for source in result["sources"]:
35
+ print(source["source"], source["data"])
36
+
37
+ # Save result to JSON
38
+ client.save_json(result, "output.json")
39
+ ```
40
+
41
+ ## CLI
42
+
43
+ ```bash
44
+ # Query entities
45
+ interopdb gene rpoB
46
+ interopdb strain 511145
47
+
48
+ # Query a gene-strain pair
49
+ interopdb pair rpoB 511145
50
+
51
+ # Save to file
52
+ interopdb gene rpoB -o result.json
53
+ ```
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "interopdb"
7
+ version = "0.1.0"
8
+ description = "Python client for the Interop DB Registry API"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ "httpx>=0.24",
13
+ "click>=8.0",
14
+ ]
15
+
16
+ [project.optional-dependencies]
17
+ dev = ["pytest>=7.0", "pytest-httpx>=0.21"]
18
+
19
+ [project.scripts]
20
+ interopdb = "interopdb.cli:cli"
21
+
22
+ [tool.setuptools.packages.find]
23
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,4 @@
1
+ from interopdb.client import InteropClient
2
+
3
+ __all__ = ["InteropClient"]
4
+ __version__ = "0.1.0"
@@ -0,0 +1,60 @@
1
+ """Command-line interface for querying the Interop DB Registry."""
2
+
3
+ import json
4
+ import sys
5
+
6
+ import click
7
+ from interopdb.client import DEFAULT_BASE_URL, InteropClient, InteropError
8
+
9
+
10
+ @click.group()
11
+ @click.option("--url", default=DEFAULT_BASE_URL, show_default=True, help="Interop DB server URL.")
12
+ @click.pass_context
13
+ def cli(ctx, url):
14
+ """Query the Interop DB Registry."""
15
+ ctx.ensure_object(dict)
16
+ ctx.obj["client"] = InteropClient(base_url=url)
17
+
18
+
19
+ @cli.command()
20
+ @click.argument("identifier")
21
+ @click.option("-o", "--output", type=click.Path(), help="Save result to a JSON file.")
22
+ @click.pass_context
23
+ def gene(ctx, identifier, output):
24
+ """Query a gene by local ID or UID."""
25
+ _query(ctx.obj["client"].get_gene, identifier, output)
26
+
27
+
28
+ @cli.command()
29
+ @click.argument("identifier")
30
+ @click.option("-o", "--output", type=click.Path(), help="Save result to a JSON file.")
31
+ @click.pass_context
32
+ def strain(ctx, identifier, output):
33
+ """Query a strain by local ID or UID."""
34
+ _query(ctx.obj["client"].get_strain, identifier, output)
35
+
36
+
37
+ @cli.command()
38
+ @click.argument("gene_id")
39
+ @click.argument("strain_id")
40
+ @click.option("-o", "--output", type=click.Path(), help="Save result to a JSON file.")
41
+ @click.pass_context
42
+ def pair(ctx, gene_id, strain_id, output):
43
+ """Query a gene-strain pair across all source databases."""
44
+ _query(lambda _=None: ctx.obj["client"].get_pair(gene_id, strain_id), None, output)
45
+
46
+
47
+ def _query(func, identifier, output):
48
+ try:
49
+ result = func(identifier) if identifier is not None else func()
50
+ except InteropError as e:
51
+ click.secho(f"Error: {e}", fg="red", err=True)
52
+ sys.exit(1)
53
+
54
+ formatted = json.dumps(result, indent=2, ensure_ascii=False)
55
+
56
+ if output:
57
+ InteropClient.save_json(result, output)
58
+ click.echo(f"Saved to {output}")
59
+ else:
60
+ click.echo(formatted)
@@ -0,0 +1,96 @@
1
+ """Interop DB Registry API client."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ import httpx
7
+
8
+ DEFAULT_BASE_URL = "https://interopdb-staging-f-ca.salmonpebble-cac1724c.northeurope.azurecontainerapps.io"
9
+ DEFAULT_TIMEOUT = 120.0
10
+
11
+
12
+ class InteropError(Exception):
13
+ """Raised when an API request fails."""
14
+
15
+ def __init__(self, status_code: int, detail: str):
16
+ self.status_code = status_code
17
+ self.detail = detail
18
+ super().__init__(f"HTTP {status_code}: {detail}")
19
+
20
+
21
+ class InteropClient:
22
+ """Client for querying the Interop DB Registry API.
23
+
24
+ Args:
25
+ base_url: Base URL of the Interop DB server.
26
+ timeout: Request timeout in seconds.
27
+ """
28
+
29
+ def __init__(
30
+ self,
31
+ base_url: str = DEFAULT_BASE_URL,
32
+ timeout: float = DEFAULT_TIMEOUT,
33
+ ):
34
+ self.base_url = base_url.rstrip("/")
35
+ self._client = httpx.Client(base_url=self.base_url, timeout=timeout)
36
+
37
+ def get_gene(self, identifier: str) -> dict:
38
+ """Query a gene by local ID or UID.
39
+
40
+ Args:
41
+ identifier: Gene local ID (e.g. ``"rpoB"``) or UID (e.g. ``"G-6EE9A9CD8006"``).
42
+
43
+ Returns:
44
+ Registry item with ``local_id``, ``uid``, ``entity_type``, and ``attributes`` from all source databases.
45
+ """
46
+ return self._get(f"/gene/{identifier}")
47
+
48
+ def get_strain(self, identifier: str) -> dict:
49
+ """Query a strain by local ID or UID.
50
+
51
+ Args:
52
+ identifier: Strain local ID (e.g. ``"511145"``) or UID (e.g. ``"S-6AC722234E99"``).
53
+
54
+ Returns:
55
+ Registry item with ``local_id``, ``uid``, ``entity_type``, and ``attributes`` from all source databases.
56
+ """
57
+ return self._get(f"/strain/{identifier}")
58
+
59
+ def get_pair(self, gene_id: str, strain_id: str) -> dict:
60
+ """Query a gene-strain pair across all source databases.
61
+
62
+ Args:
63
+ gene_id: Gene local ID or UID.
64
+ strain_id: Strain local ID or UID.
65
+
66
+ Returns:
67
+ Pair result with ``gene``, ``strain``, and ``sources`` list containing data from each database.
68
+ """
69
+ return self._get(f"/pair/{gene_id},{strain_id}")
70
+
71
+ def _get(self, path: str) -> dict:
72
+ response = self._client.get(path)
73
+ if response.status_code == 200:
74
+ return response.json()
75
+ detail = response.text or response.reason_phrase
76
+ raise InteropError(response.status_code, detail)
77
+
78
+ @staticmethod
79
+ def save_json(data: dict, path: str | Path) -> None:
80
+ """Save a result dictionary to a JSON file.
81
+
82
+ Args:
83
+ data: Result from ``get_gene``, ``get_strain``, or ``get_pair``.
84
+ path: Output file path.
85
+ """
86
+ path = Path(path)
87
+ path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n")
88
+
89
+ def close(self) -> None:
90
+ self._client.close()
91
+
92
+ def __enter__(self):
93
+ return self
94
+
95
+ def __exit__(self, *args):
96
+ self.close()
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: interopdb
3
+ Version: 0.1.0
4
+ Summary: Python client for the Interop DB Registry API
5
+ Requires-Python: >=3.9
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: httpx>=0.24
8
+ Requires-Dist: click>=8.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=7.0; extra == "dev"
11
+ Requires-Dist: pytest-httpx>=0.21; extra == "dev"
12
+
13
+ # interopdb
14
+
15
+ Python client and CLI for the [Interop DB Registry](https://interopdb-staging-f-ca.salmonpebble-cac1724c.northeurope.azurecontainerapps.io/) API.
16
+
17
+ Interop DB is a federated registry that assigns unified identifiers to genes and strains across multiple biological databases, enabling cross-database queries with a single search. It integrates data from:
18
+
19
+ - **ALEdb** -- Adaptive Laboratory Evolution Database
20
+ - **BiGGr** -- Knowledgebase of genome-scale metabolic network reconstructions
21
+ - **PanKB** -- Pangenome Knowledge Base (genes, strains, pangenomics)
22
+ - **PMkbase** -- Phenotype MicroArray Knowledge Base (strains, phenotypes)
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install interopdb
28
+ ```
29
+
30
+ ## Python API
31
+
32
+ ```python
33
+ from interopdb import InteropClient
34
+
35
+ client = InteropClient()
36
+
37
+ # Query a gene
38
+ result = client.get_gene("rpoB")
39
+ print(result["uid"], result["attributes"])
40
+
41
+ # Query a strain
42
+ result = client.get_strain("511145")
43
+
44
+ # Query a gene-strain pair
45
+ result = client.get_pair("rpoB", "511145")
46
+ for source in result["sources"]:
47
+ print(source["source"], source["data"])
48
+
49
+ # Save result to JSON
50
+ client.save_json(result, "output.json")
51
+ ```
52
+
53
+ ## CLI
54
+
55
+ ```bash
56
+ # Query entities
57
+ interopdb gene rpoB
58
+ interopdb strain 511145
59
+
60
+ # Query a gene-strain pair
61
+ interopdb pair rpoB 511145
62
+
63
+ # Save to file
64
+ interopdb gene rpoB -o result.json
65
+ ```
@@ -0,0 +1,11 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/interopdb/__init__.py
4
+ src/interopdb/cli.py
5
+ src/interopdb/client.py
6
+ src/interopdb.egg-info/PKG-INFO
7
+ src/interopdb.egg-info/SOURCES.txt
8
+ src/interopdb.egg-info/dependency_links.txt
9
+ src/interopdb.egg-info/entry_points.txt
10
+ src/interopdb.egg-info/requires.txt
11
+ src/interopdb.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ interopdb = interopdb.cli:cli
@@ -0,0 +1,6 @@
1
+ httpx>=0.24
2
+ click>=8.0
3
+
4
+ [dev]
5
+ pytest>=7.0
6
+ pytest-httpx>=0.21
@@ -0,0 +1 @@
1
+ interopdb