kapso-python 0.1.0a1__tar.gz → 0.1.0a2__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.
Files changed (28) hide show
  1. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/CHANGELOG.md +10 -0
  2. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/PKG-INFO +4 -4
  3. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/README.md +1 -1
  4. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/pyproject.toml +7 -3
  5. kapso_python-0.1.0a1/.env.example +0 -8
  6. kapso_python-0.1.0a1/.github/dependabot.yml +0 -10
  7. kapso_python-0.1.0a1/.github/workflows/ci.yml +0 -47
  8. kapso_python-0.1.0a1/.github/workflows/release.yml +0 -48
  9. kapso_python-0.1.0a1/.python-version +0 -1
  10. kapso_python-0.1.0a1/examples/fastapi_receiver.py +0 -106
  11. kapso_python-0.1.0a1/uv.lock +0 -1888
  12. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/.gitignore +0 -0
  13. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/LICENSE +0 -0
  14. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/__init__.py +0 -0
  15. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/client.py +0 -0
  16. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/errors.py +0 -0
  17. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/messages/__init__.py +0 -0
  18. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/messages/models.py +0 -0
  19. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/messages/resource.py +0 -0
  20. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/py.typed +0 -0
  21. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/types.py +0 -0
  22. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/webhooks/__init__.py +0 -0
  23. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/webhooks/parse.py +0 -0
  24. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/webhooks/payloads.py +0 -0
  25. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/src/kapso/webhooks/signature.py +0 -0
  26. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/tests/test_client.py +0 -0
  27. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/tests/test_parse.py +0 -0
  28. {kapso_python-0.1.0a1 → kapso_python-0.1.0a2}/tests/test_webhooks.py +0 -0
@@ -6,6 +6,16 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.0a2] - 2026-11-30
10
+
11
+ ### Fixed
12
+ - Cap dependencies at their current major versions (`httpx<1`, `pydantic<3`). With pre-releases
13
+ allowed (e.g. `uv add --prerelease=allow`), 0.1.0a1 could resolve httpx `1.0.devN`, which has no
14
+ `httpx.AsyncClient`, and fail on import.
15
+
16
+ ### Changed
17
+ - Smaller source distribution: only the package, tests and docs.
18
+
9
19
  ## [0.1.0a1] - 2026-11-30
10
20
 
11
21
  First alpha.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: kapso-python
3
- Version: 0.1.0a1
3
+ Version: 0.1.0a2
4
4
  Summary: Unofficial Python SDK for Kapso (WhatsApp Business): webhooks, typed payloads and an async API client.
5
5
  Project-URL: Homepage, https://github.com/Joselier3/kapso-python
6
6
  Project-URL: Repository, https://github.com/Joselier3/kapso-python
@@ -25,8 +25,8 @@ Classifier: Topic :: Communications :: Chat
25
25
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
26
  Classifier: Typing :: Typed
27
27
  Requires-Python: >=3.11
28
- Requires-Dist: httpx>=0.28.1
29
- Requires-Dist: pydantic>=2.14.4
28
+ Requires-Dist: httpx<1,>=0.28.1
29
+ Requires-Dist: pydantic<3,>=2.14.4
30
30
  Description-Content-Type: text/markdown
31
31
 
32
32
  # kapso-python
@@ -39,7 +39,7 @@ A Python SDK for [Kapso](https://kapso.ai) (WhatsApp Business), built from real
39
39
  > Early and learning-driven (alpha): the API will change.
40
40
 
41
41
  ```bash
42
- uv add "kapso-python @ git+https://github.com/Joselier3/kapso-python" # until the first PyPI release
42
+ uv add kapso-python # or: pip install kapso-python
43
43
  ```
44
44
 
45
45
  ```python
@@ -8,7 +8,7 @@ A Python SDK for [Kapso](https://kapso.ai) (WhatsApp Business), built from real
8
8
  > Early and learning-driven (alpha): the API will change.
9
9
 
10
10
  ```bash
11
- uv add "kapso-python @ git+https://github.com/Joselier3/kapso-python" # until the first PyPI release
11
+ uv add kapso-python # or: pip install kapso-python
12
12
  ```
13
13
 
14
14
  ```python
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kapso-python"
3
- version = "0.1.0a1"
3
+ version = "0.1.0a2"
4
4
  description = "Unofficial Python SDK for Kapso (WhatsApp Business): webhooks, typed payloads and an async API client."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -25,8 +25,8 @@ classifiers = [
25
25
  "Typing :: Typed",
26
26
  ]
27
27
  dependencies = [
28
- "httpx>=0.28.1",
29
- "pydantic>=2.14.4",
28
+ "httpx>=0.28.1,<1",
29
+ "pydantic>=2.14.4,<3",
30
30
  ]
31
31
 
32
32
  [project.urls]
@@ -52,6 +52,10 @@ build-backend = "hatchling.build"
52
52
  # distribution is "kapso-python", import name is "kapso"
53
53
  packages = ["src/kapso"]
54
54
 
55
+ [tool.hatch.build.targets.sdist]
56
+ # Source release: the package, its tests and docs (pyproject.toml is always included).
57
+ include = ["src/kapso", "tests/*.py", "README.md", "CHANGELOG.md", "LICENSE"]
58
+
55
59
  [tool.fastapi]
56
60
  entrypoint = "examples.fastapi_receiver:app"
57
61
 
@@ -1,8 +0,0 @@
1
- # Config for the example app and the tests. The library itself never reads this file.
2
- # Copy to .env and fill in. .env is gitignored.
3
-
4
- # The secret you set on the Kapso WhatsApp webhook (used to verify X-Webhook-Signature).
5
- WEBHOOK_SECRET=
6
-
7
- # Kapso project API key (Kapso dashboard -> API keys). Needed for outbound calls.
8
- KAPSO_API_KEY=
@@ -1,10 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: github-actions
4
- directory: /
5
- schedule:
6
- interval: monthly
7
- - package-ecosystem: uv
8
- directory: /
9
- schedule:
10
- interval: monthly
@@ -1,47 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches: [main]
6
- pull_request:
7
-
8
- permissions:
9
- contents: read
10
-
11
- concurrency:
12
- group: ci-${{ github.ref }}
13
- cancel-in-progress: true
14
-
15
- jobs:
16
- lint:
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v7
20
- - uses: astral-sh/setup-uv@v7
21
- - run: uv sync --locked
22
- - run: uv run ruff check .
23
- - run: uv run ruff format --check .
24
-
25
- test:
26
- runs-on: ubuntu-latest
27
- strategy:
28
- fail-fast: false
29
- matrix:
30
- python-version: ["3.11", "3.12", "3.13", "3.14"]
31
- steps:
32
- - uses: actions/checkout@v7
33
- - uses: astral-sh/setup-uv@v7
34
- with:
35
- python-version: ${{ matrix.python-version }}
36
- - run: uv sync --locked
37
- # Tests that need private webhook captures or WEBHOOK_SECRET skip here by design.
38
- - run: uv run pytest -q -rs
39
-
40
- build:
41
- runs-on: ubuntu-latest
42
- steps:
43
- - uses: actions/checkout@v7
44
- - uses: astral-sh/setup-uv@v7
45
- - run: uv build
46
- # The wheel must import on its own, without the repo's src/ on the path.
47
- - run: uv run --isolated --no-project --with dist/*.whl python -c "import kapso; print(kapso.__all__)"
@@ -1,48 +0,0 @@
1
- name: Release
2
-
3
- # Publishes to PyPI when a GitHub release is published (e.g. tag v0.1.0a1).
4
- # Uses PyPI trusted publishing (OIDC): no API token is stored anywhere.
5
- # One-time setup on pypi.org: add a pending trusted publisher for
6
- # owner Joselier3, repo kapso-python, workflow release.yml, environment pypi.
7
-
8
- on:
9
- release:
10
- types: [published]
11
-
12
- permissions:
13
- contents: read
14
-
15
- jobs:
16
- build:
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v7
20
- - uses: astral-sh/setup-uv@v7
21
- - run: uv sync --locked
22
- - run: uv run ruff check .
23
- - run: uv run pytest -q
24
- - name: Check the tag matches the package version
25
- run: |
26
- version=$(uv version --short)
27
- if [ "v$version" != "${{ github.event.release.tag_name }}" ]; then
28
- echo "Tag ${{ github.event.release.tag_name }} does not match version $version in pyproject.toml"
29
- exit 1
30
- fi
31
- - run: uv build
32
- - uses: actions/upload-artifact@v7
33
- with:
34
- name: dist
35
- path: dist/
36
-
37
- publish:
38
- needs: build
39
- runs-on: ubuntu-latest
40
- environment: pypi
41
- permissions:
42
- id-token: write # required for trusted publishing
43
- steps:
44
- - uses: actions/download-artifact@v8
45
- with:
46
- name: dist
47
- path: dist/
48
- - uses: pypa/gh-action-pypi-publish@release/v1
@@ -1 +0,0 @@
1
- 3.11
@@ -1,106 +0,0 @@
1
- """Example app: receive Kapso WhatsApp webhooks with FastAPI and reply to each message.
2
-
3
- This is an application, not part of the library: it reads its own config from .env,
4
- saves each verified delivery to tests/fixtures/ (gitignored) for replay in tests,
5
- and logs identifiers only.
6
-
7
- uv run fastapi dev examples/fastapi_receiver.py
8
- """
9
-
10
- import json
11
- import logging
12
- import os
13
- from contextlib import asynccontextmanager
14
- from datetime import datetime
15
- from pathlib import Path
16
-
17
- from dotenv import load_dotenv
18
- from fastapi import BackgroundTasks, FastAPI, HTTPException, Request, status
19
-
20
- from kapso import InboundMessage, KapsoClient, KapsoError, parse, verify
21
-
22
- load_dotenv()
23
-
24
- # Uvicorn only configures its own loggers; this gives ours a handler and a format.
25
- logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
26
- # Log identifiers only (IDs, types, counts): never message text, phone numbers, names or media URLs.
27
- log = logging.getLogger("fastapi_receiver")
28
-
29
- FIXTURES = Path(__file__).resolve().parents[1] / "tests" / "fixtures"
30
-
31
- # Fail closed: refuse to start without config instead of misbehaving later.
32
- KAPSO_WEBHOOK_SECRET = os.getenv("WEBHOOK_SECRET")
33
- if not KAPSO_WEBHOOK_SECRET:
34
- raise RuntimeError("WEBHOOK_SECRET is not set. Add it to .env (the secret configured on the Kapso webhook).")
35
-
36
- KAPSO_API_KEY = os.getenv("KAPSO_API_KEY")
37
- if not KAPSO_API_KEY:
38
- raise RuntimeError("KAPSO_API_KEY is not set. Add it to .env (the Kapso project API key).")
39
-
40
-
41
- @asynccontextmanager
42
- async def lifespan(app: FastAPI):
43
- # One client (one connection pool) for the whole app, closed on shutdown/reload.
44
- async with KapsoClient(KAPSO_API_KEY) as client:
45
- app.state.kapso = client
46
- yield
47
-
48
-
49
- app = FastAPI(lifespan=lifespan)
50
-
51
-
52
- async def safe_send(client: KapsoClient, msg: InboundMessage, text: str) -> None:
53
- """Reply to `msg`. Runs after the 200 has gone out, so nobody would see an exception:
54
- log failures here instead (identifiers only)."""
55
- try:
56
- wamid = await client.messages.send_text(msg.phone_number_id, msg.sender_phone, text)
57
- log.info(" replied to=%s reply=%s", msg.message_id, wamid)
58
- except KapsoError as e:
59
- log.error(" reply failed to=%s status=%s code=%s: %s", msg.message_id, e.status_code, e.code, e.message)
60
- except Exception:
61
- log.exception(" reply failed to=%s: unexpected error", msg.message_id)
62
-
63
-
64
- @app.get("/health")
65
- def health_check():
66
- return {"ok": True}
67
-
68
-
69
- @app.post("/webhooks/kapso")
70
- async def reply(req: Request, background: BackgroundTasks):
71
- raw_bytes = await req.body()
72
-
73
- signature_header = req.headers.get("x-webhook-signature")
74
- event = req.headers.get("x-webhook-event")
75
- delivery_id = req.headers.get("x-idempotency-key") # same value on Kapso's retries
76
-
77
- # Guard clause: reject anything not signed by Kapso before touching it.
78
- if not verify(raw_bytes, signature_header, KAPSO_WEBHOOK_SECRET):
79
- log.warning("rejected delivery=%s event=%s: invalid signature (%d bytes)", delivery_id, event, len(raw_bytes))
80
- raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid signature")
81
-
82
- messages = parse(raw_bytes, event)
83
- log.info("delivery=%s event=%s messages=%d", delivery_id, event, len(messages))
84
-
85
- client: KapsoClient = req.app.state.kapso
86
- for msg in messages:
87
- log.info(
88
- " message id=%s conversation=%s type=%s media=%s",
89
- msg.message_id,
90
- msg.conversation_id,
91
- msg.type,
92
- msg.media.mime_type if msg.media else None,
93
- )
94
- if msg.sender_phone is None: # BSUID-only sender: send_text needs a phone number for now
95
- log.warning(" skipped id=%s: no sender phone", msg.message_id)
96
- continue
97
- # Runs after the response: Kapso gets its 200 right away and doesn't retry.
98
- # Still no dedup: if Kapso does retry a delivery, this replies twice (exercise 4).
99
- background.add_task(safe_send, client, msg, "Hola, mundo!")
100
-
101
- FIXTURES.mkdir(parents=True, exist_ok=True)
102
- name = datetime.now().strftime("%Y%m%d-%H%M%S-%f")
103
- (FIXTURES / f"{name}.body").write_bytes(raw_bytes)
104
- (FIXTURES / f"{name}.headers.json").write_text(json.dumps(dict(req.headers), indent=2))
105
-
106
- return {"ok": True}