aidbox-python-sdk 0.2.2__py3-none-any.whl → 0.3.0__py3-none-any.whl

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.
@@ -1,8 +1,8 @@
1
1
  __title__ = "aidbox-python-sdk"
2
- __version__ = "0.2.2"
2
+ __version__ = "0.3.0"
3
3
  __author__ = "beda.software"
4
4
  __license__ = "None"
5
- __copyright__ = "Copyright 2024 beda.software"
5
+ __copyright__ = "Copyright 2026 beda.software"
6
6
 
7
7
  # Version synonym
8
8
  VERSION = __version__
aidbox_python_sdk/db.py CHANGED
@@ -22,6 +22,36 @@ from aidbox_python_sdk.settings import Settings
22
22
 
23
23
  from .exceptions import AidboxDBException
24
24
 
25
+
26
+ def parse_psql_response(response):
27
+ """
28
+ Normalizes a $psql response into a list of result sets (one per statement).
29
+ Supports both formats:
30
+ - pre-2604: [{status, result: [row, ...], ...}]
31
+ - 2604+: {status, result: [{type, data: [row, ...]}, ...], ...}
32
+ Raises AidboxDBException on error status.
33
+ """
34
+ entry = response[0] if isinstance(response, list) else response
35
+
36
+ if entry.get("status") == "error":
37
+ raise AidboxDBException(entry)
38
+
39
+ result = entry.get("result")
40
+
41
+ if not isinstance(result, list):
42
+ return [result] # None or True (old format execute=true)
43
+
44
+ if not result:
45
+ return [result]
46
+
47
+ # New format (2604+): result items carry {type, data}
48
+ if isinstance(result[0], dict) and "data" in result[0]:
49
+ return [rset["data"] for rset in result]
50
+
51
+ # Old format: single flat list of rows
52
+ return [result]
53
+
54
+
25
55
  logger = logging.getLogger("aidbox_sdk.db")
26
56
  table_metadata = MetaData()
27
57
 
@@ -124,10 +154,17 @@ class DBProxy:
124
154
  ) as resp:
125
155
  logger.debug("$psql answer %s", await resp.text())
126
156
  results = await resp.json()
127
-
128
- if results[0]["status"] == "error":
129
- raise AidboxDBException(results[0])
130
- return results[0].get("result", None)
157
+ result = parse_psql_response(results)
158
+ if execute:
159
+ return True
160
+ if len(result) > 1:
161
+ raise AidboxDBException(
162
+ {
163
+ "status": "error",
164
+ "error": "Multiple result sets returned; use execute=True for multi-statement queries",
165
+ }
166
+ )
167
+ return result[0]
131
168
 
132
169
  def compile_statement(self, statement):
133
170
  return str(
@@ -1,5 +1,7 @@
1
1
  import asyncio
2
+ import base64
2
3
  import logging
4
+ import secrets
3
5
  from typing import Any
4
6
 
5
7
  from aiohttp import web
@@ -11,6 +13,13 @@ logger = logging.getLogger("aidbox_sdk")
11
13
  routes = web.RouteTableDef()
12
14
 
13
15
 
16
+ def is_from_aidbox(request: web.Request) -> bool:
17
+ """Aidbox calls an http-rpc endpoint with the secret the app registered it under."""
18
+ settings = request.app[ak.settings]
19
+ expected = b"Basic " + base64.b64encode(f"{settings.APP_ID}:{settings.APP_SECRET}".encode())
20
+ return secrets.compare_digest(request.headers.get("Authorization", "").encode(), expected)
21
+
22
+
14
23
  async def subscription(request: web.Request, data: dict):
15
24
  logger.debug("Subscription handler: %s", data["handler"])
16
25
  if "handler" not in data or "event" not in data:
@@ -59,6 +68,10 @@ TYPES = {
59
68
  @routes.post("/aidbox")
60
69
  async def dispatch(request):
61
70
  logger.debug("Dispatch new request %s %s", request.method, request.url)
71
+ if not is_from_aidbox(request):
72
+ logger.error("Dispatch request without the app's credentials")
73
+ raise web.HTTPUnauthorized()
74
+
62
75
  data = await request.json()
63
76
  if "type" in data and data["type"] in TYPES:
64
77
  logger.debug("Dispatch to `%s` handler", data["type"])
@@ -13,6 +13,7 @@ from yarl import URL
13
13
  from aidbox_python_sdk.aidboxpy import AsyncAidboxClient
14
14
 
15
15
  from . import app_keys as ak
16
+ from .db import parse_psql_response
16
17
 
17
18
  _TEST_SERVER_URL = "http://127.0.0.1:8081"
18
19
 
@@ -100,7 +101,7 @@ async def safe_db(aidbox_client: AsyncAidboxClient, sdk):
100
101
  "/$psql",
101
102
  data={"query": "SELECT last_value from transaction_id_seq;"},
102
103
  )
103
- txid = results[0]["result"][0]["last_value"]
104
+ txid = parse_psql_response(results)[0][0]["last_value"]
104
105
  sdk._test_start_txid = int(txid)
105
106
 
106
107
  yield txid
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aidbox-python-sdk
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Aidbox SDK for python
5
5
  Author-email: "beda.software" <aidbox-python-sdk@beda.software>
6
6
  License: MIT License
@@ -35,13 +35,13 @@ Classifier: Intended Audience :: Developers
35
35
  Classifier: Operating System :: OS Independent
36
36
  Classifier: Programming Language :: Python
37
37
  Classifier: Programming Language :: Python :: 3
38
- Classifier: Programming Language :: Python :: 3.9
39
- Classifier: Programming Language :: Python :: 3.10
40
38
  Classifier: Programming Language :: Python :: 3.11
41
39
  Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Programming Language :: Python :: 3.13
41
+ Classifier: Programming Language :: Python :: 3.14
42
42
  Classifier: Topic :: Internet :: WWW/HTTP
43
43
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
44
- Requires-Python: >=3.9
44
+ Requires-Python: >=3.11
45
45
  Description-Content-Type: text/markdown
46
46
  License-File: LICENSE.md
47
47
  Requires-Dist: aiohttp>=3.11.0
@@ -62,11 +62,11 @@ Dynamic: license-file
62
62
 
63
63
  [![build status](https://github.com/Aidbox/aidbox-python-sdk/actions/workflows/build.yaml/badge.svg)](https://github.com/Aidbox/aidbox-python-sdk/actions/workflows/build.yaml)
64
64
  [![pypi](https://img.shields.io/pypi/v/aidbox-python-sdk.svg)](https://pypi.org/project/aidbox-python-sdk/)
65
- [![Supported Python version](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/)
65
+ [![Supported Python version](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/release/python-3110/)
66
66
 
67
67
  # aidbox-python-sdk
68
68
 
69
- 1. Create a python 3.9+ environment `pyenv `
69
+ 1. Create a python 3.11+ environment `pyenv `
70
70
  2. Set env variables and activate virtual environment `source activate_settings.sh`
71
71
  2. Install the required packages with `pipenv install --dev`
72
72
  3. Make sure the app's settings are configured correctly (see `activate_settings.sh` and `aidbox_python_sdk/settings.py`). You can also
@@ -1,18 +1,18 @@
1
- aidbox_python_sdk/__init__.py,sha256=1RLAoHkquc4ZvdHZW8bzJxEU6Wv2XG2KvabPKmwvIuQ,192
1
+ aidbox_python_sdk/__init__.py,sha256=SHb4ulvXRA4YCGOkMp_wqhSzprLIHt2tOdap815_6TQ,192
2
2
  aidbox_python_sdk/aidboxpy.py,sha256=7ewo0TO1FeGU8IVPqwm6PqR7-o8zSt3EvqPi2UfEWoE,4182
3
3
  aidbox_python_sdk/app_keys.py,sha256=5ZkoJcJaUhMB-veQXVDzN_yQsOD2OOkGIIunNHujRyM,454
4
- aidbox_python_sdk/db.py,sha256=-PQ4tkqPQ2PcuUF3B1uI-G4DYM3yNwwpAlww0odZe-E,7190
4
+ aidbox_python_sdk/db.py,sha256=AQlju5V6F2l3HIxkaTbspx2gm4mBntO-gsIzhQgZW_M,8351
5
5
  aidbox_python_sdk/db_migrations.py,sha256=xzTQKPyEsWQePyvaYFuHz7auCChMdTcUW8vEeY3QtkM,1459
6
6
  aidbox_python_sdk/exceptions.py,sha256=hOn2rhEYNmuWuSiImObdd3R4xApsskmVdbVnb2PrIoA,116
7
- aidbox_python_sdk/handlers.py,sha256=YEEhAkJBTjrtArwxLs8QWK1FEKvYLW6LSVZF17NpRjk,2832
7
+ aidbox_python_sdk/handlers.py,sha256=zptJpAykS-W3ke1jc_ksax7ARkZ98NhagsFVpXvdMrE,3379
8
8
  aidbox_python_sdk/main.py,sha256=Gk-5QHo2MDQcNv7FMqmRD1JcKIJJiLdk6K4ce3Mb_pw,2464
9
9
  aidbox_python_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- aidbox_python_sdk/pytest_plugin.py,sha256=yWcbveHV3Uu0OJSN5TrJeg0-6lpFgx8SFX-oQSoXBSU,4798
10
+ aidbox_python_sdk/pytest_plugin.py,sha256=wK5NqEwd9g2eDpRNv4MyFK9_ebmo56JfL4G4nUuMtXA,4845
11
11
  aidbox_python_sdk/sdk.py,sha256=USzJryMYKGBt7SuCSt6YFjLsFqnMaTW-itxMJDl2dBo,9163
12
12
  aidbox_python_sdk/settings.py,sha256=l-zdzH3UT4Pq_OjNgFe2ELmWKSjEnBgOAcChf-FQais,3231
13
13
  aidbox_python_sdk/types.py,sha256=Oqcq4QZgOR71MwfoxW38-y9fWWUr49U5IoRS5LNbRq4,478
14
- aidbox_python_sdk-0.2.2.dist-info/licenses/LICENSE.md,sha256=Opl86pEF7tgGGO2Wkdgfavnpi-MSgNY7RVJKxtZIGlE,1066
15
- aidbox_python_sdk-0.2.2.dist-info/METADATA,sha256=jKeeliE5DvN2o60DKQ6XDPcw_PzzlbX8ZEKo1ojVocw,11470
16
- aidbox_python_sdk-0.2.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
17
- aidbox_python_sdk-0.2.2.dist-info/top_level.txt,sha256=FJCCumQP-K5JkLtm0wispLy8Hy7ftneBaMMW-g5dvpQ,18
18
- aidbox_python_sdk-0.2.2.dist-info/RECORD,,
14
+ aidbox_python_sdk-0.3.0.dist-info/licenses/LICENSE.md,sha256=Opl86pEF7tgGGO2Wkdgfavnpi-MSgNY7RVJKxtZIGlE,1066
15
+ aidbox_python_sdk-0.3.0.dist-info/METADATA,sha256=lOxyqIlT6Omau_qqQxT7-yTO-y5m3rNqsGRb-2UIsFw,11475
16
+ aidbox_python_sdk-0.3.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
17
+ aidbox_python_sdk-0.3.0.dist-info/top_level.txt,sha256=FJCCumQP-K5JkLtm0wispLy8Hy7ftneBaMMW-g5dvpQ,18
18
+ aidbox_python_sdk-0.3.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (84.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5