oushodh 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,26 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ check:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
17
+ steps:
18
+ - uses: actions/checkout@v7
19
+ - uses: astral-sh/setup-uv@v10.3.3
20
+ with:
21
+ python-version: ${{ matrix.python }}
22
+ - run: uv sync --locked
23
+ - run: uv run ruff check
24
+ - run: uv run ruff format --check
25
+ - run: uv run mypy
26
+ - run: uv run pytest
@@ -0,0 +1,23 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ environment: pypi
14
+ permissions:
15
+ contents: read
16
+ id-token: write
17
+ steps:
18
+ - uses: actions/checkout@v7
19
+ - uses: astral-sh/setup-uv@v10.3.3
20
+ - run: uv sync --locked
21
+ - run: uv run pytest
22
+ - run: uv build
23
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ dist/
5
+ .mypy_cache/
6
+ .pytest_cache/
7
+ .ruff_cache/
@@ -0,0 +1 @@
1
+ 3.10
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (12 Nov, 2026)
4
+
5
+ - First version of the Python SDK for the Oushodh API `/v1`.
6
+ - `Oushodh` and `AsyncOushodh` clients: `meta()`, `list_medicines()`, `medicines()` (pages to the end), `search()`,
7
+ `get_medicine()`, `image_url()` and `get_image()`.
8
+ - Typed models for `Medicine`, `MedicineDetail`, `Monograph`, `Page`, `SearchResult` and `Meta`. Unknown fields are kept.
9
+ - Errors by family, each with `status`, `code` and `message`.
10
+ - Retries on `429 rate_limited` (honours `Retry-After`), `5xx` and network errors.
oushodh-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Oushodh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
oushodh-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.5
2
+ Name: oushodh
3
+ Version: 0.1.0
4
+ Summary: Python SDK for the Oushodh medicine data API
5
+ Project-URL: Homepage, https://oushodh.dev
6
+ Project-URL: Documentation, https://oushodh.dev/docs
7
+ Project-URL: Repository, https://github.com/oushodh/oushodh-python
8
+ Project-URL: Changelog, https://github.com/oushodh/oushodh-python/blob/main/CHANGELOG.md
9
+ Author-email: Oushodh <support@oushodh.dev>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: httpx>=0.28.1
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Oushodh Python SDK
23
+
24
+ The official Python client for the Oushodh API.
25
+
26
+ [![CI](https://github.com/oushodh/oushodh-python/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/oushodh/oushodh-python/actions/workflows/ci.yml)
27
+ [![Licence: MIT](https://img.shields.io/github/license/oushodh/oushodh-python)](LICENSE)
28
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-3776ab)](https://www.python.org/)
29
+
30
+ ## What Oushodh is
31
+
32
+ Oushodh serves Bangladesh medicine data over a REST API: brands, generics, prices and makers. Make a key in the member
33
+ portal at [app.oushodh.dev](https://app.oushodh.dev), and read the docs at [oushodh.dev/docs](https://oushodh.dev/docs).
34
+
35
+ The SDK needs Python 3.10 or newer. Its one dependency is [httpx](https://www.python-httpx.org/). It has a sync
36
+ client, `Oushodh`, and an async client, `AsyncOushodh`, and it is fully typed.
37
+
38
+ ## Install
39
+
40
+ Install release 0.1.0 from GitHub:
41
+
42
+ ```sh
43
+ pip install "git+https://github.com/oushodh/oushodh-python.git@v0.1.0"
44
+ # or
45
+ uv add "git+https://github.com/oushodh/oushodh-python.git@v0.1.0"
46
+ ```
47
+
48
+ Install from PyPI is coming soon.
49
+
50
+ ## Quickstart
51
+
52
+ Make a key on the Keys page of the member portal. A key starts with `oush_` and is shown once. Keep it on your
53
+ server: never put it in a web page or an app.
54
+
55
+ ```sh
56
+ export OUSHODH_API_KEY=oush_...
57
+ ```
58
+
59
+ ```python
60
+ from oushodh import Oushodh
61
+
62
+ client = Oushodh() # reads OUSHODH_API_KEY
63
+
64
+ result = client.search("paracetamol", limit=5)
65
+
66
+ for medicine in result["items"]:
67
+ print(medicine["id"], medicine["product_name"])
68
+
69
+ medicine = client.get_medicine("MED-012933")
70
+ unit = medicine["prices"]["unit"]
71
+
72
+ print(medicine["product_name"], unit and unit["amount"], "BDT a unit")
73
+ ```
74
+
75
+ `Oushodh("oush_...")` takes the key directly. With no key and no `OUSHODH_API_KEY`, it raises an `OushodhError`.
76
+
77
+ Close the client when you are done, or use it in a `with` block. `AsyncOushodh` has the same methods: await them, and
78
+ use `async for` to page.
79
+
80
+ ```python
81
+ from oushodh import AsyncOushodh
82
+
83
+ async with AsyncOushodh() as client:
84
+ async for medicine in client.medicines(q="paracetamol"):
85
+ print(medicine["id"])
86
+ ```
87
+
88
+ | Method | Route | Returns |
89
+ | ----------------------------------------------------- | ------------------------------ | ---------------------- |
90
+ | `meta()` | `GET /v1/meta` | `Meta` |
91
+ | `list_medicines(limit=, cursor=, updated_since=, q=)` | `GET /v1/medicines` | `Page` |
92
+ | `medicines(limit=, updated_since=, q=)` | `GET /v1/medicines`, each page | an iterator of `Medicine` |
93
+ | `search(q, limit=)` | `GET /v1/medicines/search` | `SearchResult` |
94
+ | `get_medicine(ref)` | `GET /v1/medicines/{ref}` | `MedicineDetail` |
95
+ | `image_url(file)` | none | the picture's address |
96
+ | `get_image(file)` | `GET /v1/images/{file}` | the picture's bytes |
97
+
98
+ `meta()` names your account and counts the medicines your plan reads. Call it to check that a key works.
99
+
100
+ `get_medicine()` takes an ID in any profile, an old ID or a UUID. The answer always carries the medicine's current
101
+ ID, and its `monograph`.
102
+
103
+ Every model is a typed dict, so it is a plain `dict` at run time, with the API's field names. A value no source gives
104
+ is `None`. Fields the API adds later are kept in the dict.
105
+
106
+ ## Paging
107
+
108
+ `list_medicines()` returns one page: `items`, `next` and `total`. Pass `next` back as `cursor` for the next page.
109
+ `next` is `None` on the last page. `limit` is 1 to 500, and 100 when you leave it out.
110
+
111
+ ```python
112
+ page = client.list_medicines(limit=500)
113
+
114
+ while True:
115
+ for medicine in page["items"]:
116
+ ...
117
+
118
+ if page["next"] is None:
119
+ break
120
+
121
+ page = client.list_medicines(limit=500, cursor=page["next"])
122
+ ```
123
+
124
+ `medicines()` does the same for you. It yields every medicine and follows `next` to the end:
125
+
126
+ ```python
127
+ for medicine in client.medicines(limit=500):
128
+ print(medicine["id"], medicine["product_name"])
129
+ ```
130
+
131
+ Search has no cursor. To page through every match, use `medicines(q=...)`.
132
+
133
+ ## Keeping a copy in sync
134
+
135
+ Copy every medicine once, then fetch only what changed.
136
+
137
+ 1. The first sync pages through every medicine and keeps the newest `last_updated`.
138
+ 2. Each later sync passes that time as `updated_since` and pages to the end. It gets the medicines changed at or after
139
+ that time, oldest change first.
140
+
141
+ ```python
142
+ since = load_last_sync() # None on the first sync
143
+
144
+ for medicine in client.medicines(limit=500, updated_since=since):
145
+ save_medicine(medicine["uuid"], medicine)
146
+
147
+ if since is None or medicine["last_updated"] > since:
148
+ since = medicine["last_updated"]
149
+
150
+ save_last_sync(since)
151
+ ```
152
+
153
+ - `updated_since` takes a string such as `2026-11-08T09:30:00Z`, or a `datetime` with a timezone. The client sends a
154
+ `datetime` in UTC, to the whole second. A `datetime` with no timezone raises a `ValueError`.
155
+ - "At or after" means a change in the same second is never missed. The medicine that set the time comes back once
156
+ more, so save by `uuid`.
157
+ - Store `uuid` as the key: it never changes. Show `id` to people.
158
+ - Medicines are never deleted and IDs are never reused, so a sync never has to remove one.
159
+
160
+ ## Images
161
+
162
+ `product_image` is the address of the medicine's picture, or `None`. `images` lists every picture, `product_image`
163
+ first. An address under `/v1/images/` is a copy Oushodh keeps. It needs no key, so an `<img>` tag can show it, and it
164
+ never changes. Any other address belongs to the source, and it can move or be removed.
165
+
166
+ `get_image()` takes the file name, not the whole address, and sends no key:
167
+
168
+ ```python
169
+ url = medicine["product_image"]
170
+
171
+ if url and url.startswith(client.image_url("")):
172
+ jpeg = client.get_image(url.rsplit("/", 1)[-1])
173
+ ```
174
+
175
+ `image_url(file)` builds the address of a file, such as
176
+ `50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c.jpg`.
177
+
178
+ ## Errors
179
+
180
+ Every error is an `OushodhError`. It has `status` (the HTTP status), `code` (the API's error code) and `message`.
181
+ Match on the class or on `code`, never on `message`: the message is for people and may change.
182
+
183
+ | Class | Status | `code` |
184
+ | ----------------------- | ------ | ---------------------------------- |
185
+ | `BadRequestError` | 400 | `bad_request` |
186
+ | `AuthenticationError` | 401 | `unauthorized` |
187
+ | `PermissionDeniedError` | 403 | `plan_expired` or `plan_limit` |
188
+ | `NotFoundError` | 404 | `not_found` |
189
+ | `RateLimitError` | 429 | `rate_limited` or `quota_exceeded` |
190
+ | `InternalServerError` | 5xx | `internal` |
191
+ | `APIConnectionError` | none | none: the network failed |
192
+ | `APITimeoutError` | none | none: the request timed out |
193
+
194
+ `APITimeoutError` is an `APIConnectionError`. Both have `status` and `code` set to `None`. When an error body is not
195
+ JSON, `code` is `None` and the message is `HTTP <status>`. The key never appears in an error message.
196
+
197
+ ```python
198
+ from oushodh import NotFoundError, PermissionDeniedError
199
+
200
+ try:
201
+ medicine = client.get_medicine("MED-999999")
202
+ except NotFoundError:
203
+ medicine = None # No medicine has that ID.
204
+ except PermissionDeniedError as error:
205
+ if error.code != "plan_limit":
206
+ raise
207
+
208
+ medicine = None # The medicine is beyond the medicines your plan reads.
209
+ ```
210
+
211
+ ## Retries and rate limits
212
+
213
+ Your plan sets how many requests each key may make in a minute (60 a minute on Developer). It also sets how many
214
+ requests your account may make in a month. See [Rate limits](https://oushodh.dev/docs/rate-limits).
215
+
216
+ - Over the minute's limit, the API answers `429 rate_limited`. The `Retry-After` header says how many seconds to wait.
217
+ The client waits that long and tries again, up to `max_retries` times. After that it raises a `RateLimitError` with
218
+ the seconds in `retry_after`.
219
+ - When the month's requests are used up, the API answers `429 quota_exceeded` until the next month. The client never
220
+ retries it. It raises a `RateLimitError` at once, and `retry_after` counts the seconds to the next month.
221
+ - After a `5xx`, a network error or a timeout, the client backs off and tries again, up to `max_retries` times. Each
222
+ wait is about twice the last, with a random part, and at most 8 seconds.
223
+ - The client never retries a `400`, `401`, `403` or `404`: the same request gets the same answer.
224
+
225
+ Every route is a `GET`, so a retry is always safe.
226
+
227
+ ## Plan limits
228
+
229
+ Developer reads the first 5,000 medicines and Team the first 20,000, in the order of their permanent number. Agency
230
+ and Custom read all of them.
231
+
232
+ Lists and search leave out the medicines beyond your plan's number. A lookup by ID of such a medicine answers
233
+ `403 plan_limit`: the client raises a `PermissionDeniedError` with `code` `plan_limit`. An account with no active plan
234
+ gets `403 plan_expired` on every call.
235
+
236
+ ## Configuration
237
+
238
+ Pass options to the client as keyword arguments:
239
+
240
+ ```python
241
+ client = Oushodh("oush_...", timeout=10.0, max_retries=3)
242
+ ```
243
+
244
+ | Option | Default | What it does |
245
+ | ------------- | ------------------------- | -------------------------------------------------------------------- |
246
+ | `api_key` | `OUSHODH_API_KEY` | Your API key. |
247
+ | `base_url` | `https://api.oushodh.dev` | Where the API is. |
248
+ | `timeout` | `30.0` | Seconds to wait for each request. |
249
+ | `max_retries` | `2` | Retries after a `429 rate_limited`, a `5xx` or a network error. |
250
+ | `http_client` | a new `httpx.Client` | Your own `httpx.Client` (`httpx.AsyncClient` for `AsyncOushodh`). |
251
+
252
+ In your own tests, pass an `httpx.Client` with a mock transport, so no request leaves your machine:
253
+
254
+ ```python
255
+ import httpx
256
+
257
+ transport = httpx.MockTransport(
258
+ lambda request: httpx.Response(
259
+ 200, json={"client": "acme", "id_profile": "default", "medicines": 1, "last_import": None}
260
+ )
261
+ )
262
+ client = Oushodh("oush_test_123", http_client=httpx.Client(transport=transport))
263
+ ```
264
+
265
+ ## Development
266
+
267
+ ```sh
268
+ uv sync
269
+ uv run ruff check
270
+ uv run ruff format --check
271
+ uv run mypy
272
+ uv run pytest
273
+ ```
274
+
275
+ The tests use `httpx.MockTransport`. They never call the API.
276
+
277
+ ## Licence
278
+
279
+ MIT. Copyright Oushodh. See [LICENSE](LICENSE).
@@ -0,0 +1,258 @@
1
+ # Oushodh Python SDK
2
+
3
+ The official Python client for the Oushodh API.
4
+
5
+ [![CI](https://github.com/oushodh/oushodh-python/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/oushodh/oushodh-python/actions/workflows/ci.yml)
6
+ [![Licence: MIT](https://img.shields.io/github/license/oushodh/oushodh-python)](LICENSE)
7
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-3776ab)](https://www.python.org/)
8
+
9
+ ## What Oushodh is
10
+
11
+ Oushodh serves Bangladesh medicine data over a REST API: brands, generics, prices and makers. Make a key in the member
12
+ portal at [app.oushodh.dev](https://app.oushodh.dev), and read the docs at [oushodh.dev/docs](https://oushodh.dev/docs).
13
+
14
+ The SDK needs Python 3.10 or newer. Its one dependency is [httpx](https://www.python-httpx.org/). It has a sync
15
+ client, `Oushodh`, and an async client, `AsyncOushodh`, and it is fully typed.
16
+
17
+ ## Install
18
+
19
+ Install release 0.1.0 from GitHub:
20
+
21
+ ```sh
22
+ pip install "git+https://github.com/oushodh/oushodh-python.git@v0.1.0"
23
+ # or
24
+ uv add "git+https://github.com/oushodh/oushodh-python.git@v0.1.0"
25
+ ```
26
+
27
+ Install from PyPI is coming soon.
28
+
29
+ ## Quickstart
30
+
31
+ Make a key on the Keys page of the member portal. A key starts with `oush_` and is shown once. Keep it on your
32
+ server: never put it in a web page or an app.
33
+
34
+ ```sh
35
+ export OUSHODH_API_KEY=oush_...
36
+ ```
37
+
38
+ ```python
39
+ from oushodh import Oushodh
40
+
41
+ client = Oushodh() # reads OUSHODH_API_KEY
42
+
43
+ result = client.search("paracetamol", limit=5)
44
+
45
+ for medicine in result["items"]:
46
+ print(medicine["id"], medicine["product_name"])
47
+
48
+ medicine = client.get_medicine("MED-012933")
49
+ unit = medicine["prices"]["unit"]
50
+
51
+ print(medicine["product_name"], unit and unit["amount"], "BDT a unit")
52
+ ```
53
+
54
+ `Oushodh("oush_...")` takes the key directly. With no key and no `OUSHODH_API_KEY`, it raises an `OushodhError`.
55
+
56
+ Close the client when you are done, or use it in a `with` block. `AsyncOushodh` has the same methods: await them, and
57
+ use `async for` to page.
58
+
59
+ ```python
60
+ from oushodh import AsyncOushodh
61
+
62
+ async with AsyncOushodh() as client:
63
+ async for medicine in client.medicines(q="paracetamol"):
64
+ print(medicine["id"])
65
+ ```
66
+
67
+ | Method | Route | Returns |
68
+ | ----------------------------------------------------- | ------------------------------ | ---------------------- |
69
+ | `meta()` | `GET /v1/meta` | `Meta` |
70
+ | `list_medicines(limit=, cursor=, updated_since=, q=)` | `GET /v1/medicines` | `Page` |
71
+ | `medicines(limit=, updated_since=, q=)` | `GET /v1/medicines`, each page | an iterator of `Medicine` |
72
+ | `search(q, limit=)` | `GET /v1/medicines/search` | `SearchResult` |
73
+ | `get_medicine(ref)` | `GET /v1/medicines/{ref}` | `MedicineDetail` |
74
+ | `image_url(file)` | none | the picture's address |
75
+ | `get_image(file)` | `GET /v1/images/{file}` | the picture's bytes |
76
+
77
+ `meta()` names your account and counts the medicines your plan reads. Call it to check that a key works.
78
+
79
+ `get_medicine()` takes an ID in any profile, an old ID or a UUID. The answer always carries the medicine's current
80
+ ID, and its `monograph`.
81
+
82
+ Every model is a typed dict, so it is a plain `dict` at run time, with the API's field names. A value no source gives
83
+ is `None`. Fields the API adds later are kept in the dict.
84
+
85
+ ## Paging
86
+
87
+ `list_medicines()` returns one page: `items`, `next` and `total`. Pass `next` back as `cursor` for the next page.
88
+ `next` is `None` on the last page. `limit` is 1 to 500, and 100 when you leave it out.
89
+
90
+ ```python
91
+ page = client.list_medicines(limit=500)
92
+
93
+ while True:
94
+ for medicine in page["items"]:
95
+ ...
96
+
97
+ if page["next"] is None:
98
+ break
99
+
100
+ page = client.list_medicines(limit=500, cursor=page["next"])
101
+ ```
102
+
103
+ `medicines()` does the same for you. It yields every medicine and follows `next` to the end:
104
+
105
+ ```python
106
+ for medicine in client.medicines(limit=500):
107
+ print(medicine["id"], medicine["product_name"])
108
+ ```
109
+
110
+ Search has no cursor. To page through every match, use `medicines(q=...)`.
111
+
112
+ ## Keeping a copy in sync
113
+
114
+ Copy every medicine once, then fetch only what changed.
115
+
116
+ 1. The first sync pages through every medicine and keeps the newest `last_updated`.
117
+ 2. Each later sync passes that time as `updated_since` and pages to the end. It gets the medicines changed at or after
118
+ that time, oldest change first.
119
+
120
+ ```python
121
+ since = load_last_sync() # None on the first sync
122
+
123
+ for medicine in client.medicines(limit=500, updated_since=since):
124
+ save_medicine(medicine["uuid"], medicine)
125
+
126
+ if since is None or medicine["last_updated"] > since:
127
+ since = medicine["last_updated"]
128
+
129
+ save_last_sync(since)
130
+ ```
131
+
132
+ - `updated_since` takes a string such as `2026-11-08T09:30:00Z`, or a `datetime` with a timezone. The client sends a
133
+ `datetime` in UTC, to the whole second. A `datetime` with no timezone raises a `ValueError`.
134
+ - "At or after" means a change in the same second is never missed. The medicine that set the time comes back once
135
+ more, so save by `uuid`.
136
+ - Store `uuid` as the key: it never changes. Show `id` to people.
137
+ - Medicines are never deleted and IDs are never reused, so a sync never has to remove one.
138
+
139
+ ## Images
140
+
141
+ `product_image` is the address of the medicine's picture, or `None`. `images` lists every picture, `product_image`
142
+ first. An address under `/v1/images/` is a copy Oushodh keeps. It needs no key, so an `<img>` tag can show it, and it
143
+ never changes. Any other address belongs to the source, and it can move or be removed.
144
+
145
+ `get_image()` takes the file name, not the whole address, and sends no key:
146
+
147
+ ```python
148
+ url = medicine["product_image"]
149
+
150
+ if url and url.startswith(client.image_url("")):
151
+ jpeg = client.get_image(url.rsplit("/", 1)[-1])
152
+ ```
153
+
154
+ `image_url(file)` builds the address of a file, such as
155
+ `50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c.jpg`.
156
+
157
+ ## Errors
158
+
159
+ Every error is an `OushodhError`. It has `status` (the HTTP status), `code` (the API's error code) and `message`.
160
+ Match on the class or on `code`, never on `message`: the message is for people and may change.
161
+
162
+ | Class | Status | `code` |
163
+ | ----------------------- | ------ | ---------------------------------- |
164
+ | `BadRequestError` | 400 | `bad_request` |
165
+ | `AuthenticationError` | 401 | `unauthorized` |
166
+ | `PermissionDeniedError` | 403 | `plan_expired` or `plan_limit` |
167
+ | `NotFoundError` | 404 | `not_found` |
168
+ | `RateLimitError` | 429 | `rate_limited` or `quota_exceeded` |
169
+ | `InternalServerError` | 5xx | `internal` |
170
+ | `APIConnectionError` | none | none: the network failed |
171
+ | `APITimeoutError` | none | none: the request timed out |
172
+
173
+ `APITimeoutError` is an `APIConnectionError`. Both have `status` and `code` set to `None`. When an error body is not
174
+ JSON, `code` is `None` and the message is `HTTP <status>`. The key never appears in an error message.
175
+
176
+ ```python
177
+ from oushodh import NotFoundError, PermissionDeniedError
178
+
179
+ try:
180
+ medicine = client.get_medicine("MED-999999")
181
+ except NotFoundError:
182
+ medicine = None # No medicine has that ID.
183
+ except PermissionDeniedError as error:
184
+ if error.code != "plan_limit":
185
+ raise
186
+
187
+ medicine = None # The medicine is beyond the medicines your plan reads.
188
+ ```
189
+
190
+ ## Retries and rate limits
191
+
192
+ Your plan sets how many requests each key may make in a minute (60 a minute on Developer). It also sets how many
193
+ requests your account may make in a month. See [Rate limits](https://oushodh.dev/docs/rate-limits).
194
+
195
+ - Over the minute's limit, the API answers `429 rate_limited`. The `Retry-After` header says how many seconds to wait.
196
+ The client waits that long and tries again, up to `max_retries` times. After that it raises a `RateLimitError` with
197
+ the seconds in `retry_after`.
198
+ - When the month's requests are used up, the API answers `429 quota_exceeded` until the next month. The client never
199
+ retries it. It raises a `RateLimitError` at once, and `retry_after` counts the seconds to the next month.
200
+ - After a `5xx`, a network error or a timeout, the client backs off and tries again, up to `max_retries` times. Each
201
+ wait is about twice the last, with a random part, and at most 8 seconds.
202
+ - The client never retries a `400`, `401`, `403` or `404`: the same request gets the same answer.
203
+
204
+ Every route is a `GET`, so a retry is always safe.
205
+
206
+ ## Plan limits
207
+
208
+ Developer reads the first 5,000 medicines and Team the first 20,000, in the order of their permanent number. Agency
209
+ and Custom read all of them.
210
+
211
+ Lists and search leave out the medicines beyond your plan's number. A lookup by ID of such a medicine answers
212
+ `403 plan_limit`: the client raises a `PermissionDeniedError` with `code` `plan_limit`. An account with no active plan
213
+ gets `403 plan_expired` on every call.
214
+
215
+ ## Configuration
216
+
217
+ Pass options to the client as keyword arguments:
218
+
219
+ ```python
220
+ client = Oushodh("oush_...", timeout=10.0, max_retries=3)
221
+ ```
222
+
223
+ | Option | Default | What it does |
224
+ | ------------- | ------------------------- | -------------------------------------------------------------------- |
225
+ | `api_key` | `OUSHODH_API_KEY` | Your API key. |
226
+ | `base_url` | `https://api.oushodh.dev` | Where the API is. |
227
+ | `timeout` | `30.0` | Seconds to wait for each request. |
228
+ | `max_retries` | `2` | Retries after a `429 rate_limited`, a `5xx` or a network error. |
229
+ | `http_client` | a new `httpx.Client` | Your own `httpx.Client` (`httpx.AsyncClient` for `AsyncOushodh`). |
230
+
231
+ In your own tests, pass an `httpx.Client` with a mock transport, so no request leaves your machine:
232
+
233
+ ```python
234
+ import httpx
235
+
236
+ transport = httpx.MockTransport(
237
+ lambda request: httpx.Response(
238
+ 200, json={"client": "acme", "id_profile": "default", "medicines": 1, "last_import": None}
239
+ )
240
+ )
241
+ client = Oushodh("oush_test_123", http_client=httpx.Client(transport=transport))
242
+ ```
243
+
244
+ ## Development
245
+
246
+ ```sh
247
+ uv sync
248
+ uv run ruff check
249
+ uv run ruff format --check
250
+ uv run mypy
251
+ uv run pytest
252
+ ```
253
+
254
+ The tests use `httpx.MockTransport`. They never call the API.
255
+
256
+ ## Licence
257
+
258
+ MIT. Copyright Oushodh. See [LICENSE](LICENSE).
@@ -0,0 +1,48 @@
1
+ [project]
2
+ name = "oushodh"
3
+ dynamic = ["version"]
4
+ description = "Python SDK for the Oushodh medicine data API"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "Oushodh", email = "support@oushodh.dev" }]
9
+ requires-python = ">=3.10"
10
+ dependencies = ["httpx>=0.28.1"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Operating System :: OS Independent",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3 :: Only",
17
+ "Typing :: Typed",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://oushodh.dev"
22
+ Documentation = "https://oushodh.dev/docs"
23
+ Repository = "https://github.com/oushodh/oushodh-python"
24
+ Changelog = "https://github.com/oushodh/oushodh-python/blob/main/CHANGELOG.md"
25
+
26
+ [dependency-groups]
27
+ dev = ["mypy>=2.4.1", "pytest>=9.2.0", "ruff>=0.17.4"]
28
+
29
+ [build-system]
30
+ requires = ["hatchling>=1.33.0"]
31
+ build-backend = "hatchling.build"
32
+
33
+ [tool.hatch.version]
34
+ path = "src/oushodh/_version.py"
35
+
36
+ [tool.ruff]
37
+ line-length = 120
38
+ target-version = "py310"
39
+
40
+ [tool.ruff.lint]
41
+ select = ["E", "F", "W", "I", "UP", "B", "SIM", "RUF"]
42
+
43
+ [tool.mypy]
44
+ strict = true
45
+ files = ["src", "tests"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]