meibo 1.0.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.
meibo-1.0.0/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ .mypy_cache/
5
+ .venv/
6
+ dist/
7
+ build/
8
+ *.egg-info/
meibo-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,286 @@
1
+ Metadata-Version: 2.5
2
+ Name: meibo
3
+ Version: 1.0.0
4
+ Summary: SDK for meibo's directory API — school and club directories, through a key their owner hands you
5
+ Project-URL: Homepage, https://meibo.io
6
+ Project-URL: Documentation, https://meibo.io/developers/
7
+ Project-URL: Repository, https://github.com/fennecstudio/platform
8
+ Project-URL: Issues, https://github.com/fennecstudio/platform/issues
9
+ Author: Fennec Studio
10
+ License: ISC
11
+ Keywords: club,directory,meibo,roster,school,sdk
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: ISC License (ISCL)
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: httpx<1,>=0.23
25
+ Provides-Extra: dev
26
+ Requires-Dist: mypy>=1.8; extra == 'dev'
27
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
28
+ Requires-Dist: pytest>=7.4; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # meibo
32
+
33
+ Python client for the [meibo](https://meibo.io) API. Read and change a school or
34
+ club directory — its settings, its families and staff, its moderation queue and
35
+ its invites — through a key the directory's owner hands you.
36
+
37
+ ```bash
38
+ pip install meibo
39
+ ```
40
+
41
+ Python 3.10+. One dependency, [httpx](https://www.python-httpx.org), which is what
42
+ gives you a sync and an async client from the same package. The full API
43
+ reference is at [meibo.io/developers](https://meibo.io/developers/).
44
+
45
+ ## Quickstart
46
+
47
+ ```python
48
+ import os
49
+ from meibo import Meibo
50
+
51
+ meibo = Meibo(api_key=os.environ["MEIBO_API_KEY"], directory="maple")
52
+
53
+ settings = meibo.read_settings()
54
+ print(settings["name"], settings["scopes"])
55
+
56
+ written = meibo.create_entry({
57
+ "type": "family",
58
+ "name": "The Parks",
59
+ "parents": [{"name": "Min-jun Park", "email": "minjun@example.com", "phoneNumber": "555-0142"}],
60
+ "children": [{"name": "Seo-yeon", "teacher": "Mr. Chen"}],
61
+ })
62
+ print(written["id"], written["isPublished"])
63
+ ```
64
+
65
+ Every method answers the API's JSON as a `dict`, unwrapped from its
66
+ `{"success": true, "data": ...}` envelope and otherwise untouched, so its keys
67
+ are the reference's camelCase ones. The `TypedDict`s in `meibo.types` describe
68
+ each shape under the reference's own schema names, so a type checker knows
69
+ `written["isPublished"]` is a `bool`. A request body is a plain `dict` of the
70
+ same shape.
71
+
72
+ ## Async
73
+
74
+ `AsyncMeibo` has the same methods with the same arguments, awaited:
75
+
76
+ ```python
77
+ from meibo import AsyncMeibo
78
+
79
+ async with AsyncMeibo(api_key=key, directory="maple") as meibo:
80
+ page = await meibo.list_entries(q="okafor")
81
+ ```
82
+
83
+ Both clients open their connection pool on the first request. Close it when
84
+ you are done — `with Meibo(...) as meibo:`, or `meibo.close()` /
85
+ `await meibo.aclose()` — or keep one long-lived client rather than building one
86
+ per request.
87
+
88
+ ## Keys
89
+
90
+ The directory's owner makes a key on their account page at
91
+ [meibo.io/account](https://meibo.io/account/), and chooses its scopes there. It
92
+ is shown once. meibo keeps only a hash of it, so a lost key is revoked and
93
+ replaced, never recovered.
94
+
95
+ A key acts as the owner, for every directory the owner has, and follows the
96
+ owner's rules. Keep it on a server: anyone holding it can do what its scopes
97
+ allow.
98
+
99
+ Every call a key makes is logged against the directory it reached, with its
100
+ method, route and status, refusals included. The owner can read that log for 90
101
+ days.
102
+
103
+ ### Scopes
104
+
105
+ | Scope | Allows |
106
+ | --------------- | ------------------------------------------------------------------------------------------------------------ |
107
+ | `directory` | Changing the directory's name, preset, groups and logo. |
108
+ | `entries:write` | Adding entries and editing them. |
109
+ | `moderation` | Reading the moderation queue, publishing and unpublishing entries, dismissing reports, and deleting entries. |
110
+ | `invites` | Emailing families the directory's address, within its invite cap. It lets nobody in. |
111
+ | `entries:read` | Reading entries in full, contacts and children's names included. |
112
+
113
+ **`entries:read` is off unless the owner grants it.** When they do, the
114
+ dashboard tells them that what the key reads goes to the assistant's AI
115
+ provider. A key without it can still add, edit, publish and delete entries, but
116
+ what those writes answer is an entry's `id` and `isPublished`, and nothing of
117
+ what is in it. `list_moderation` without it answers a summary of each entry,
118
+ without contacts or children's names.
119
+
120
+ `read_settings` is open to any key and answers the key's own `scopes`, so call
121
+ it to find out what a key may do before trying.
122
+
123
+ ### Photos are never sent
124
+
125
+ The API serves no photos, and a key cannot send one. An entry carries
126
+ `hasPhoto` wherever the dashboard shows a photo: on the entry, and on each
127
+ parent and child. The input types here have no `photoKey`, and a body that
128
+ carries one anyway is refused with `reason` `photos`. Editing an entry keeps the
129
+ photos it already has.
130
+
131
+ ## Choosing a directory
132
+
133
+ When the owner has one directory, a key reaches it and nothing needs naming.
134
+ When they have more than one, name the directory by its slug, the last part of
135
+ its address: once on the client as `directory`, or on any call as its
136
+ `directory` argument, which wins.
137
+
138
+ ```python
139
+ from meibo import Meibo, MeiboDirectoryRequiredError
140
+
141
+ meibo = Meibo(api_key=key)
142
+
143
+ try:
144
+ meibo.read_settings()
145
+ except MeiboDirectoryRequiredError as err:
146
+ print("Pick one of:", err.directories) # ['maple', 'oak']
147
+ meibo.read_settings(directory=err.directories[0])
148
+ ```
149
+
150
+ ## Methods
151
+
152
+ Each method takes a keyword-only `directory=`, and returns the operation's
153
+ answer, already unwrapped. The names are the JavaScript SDK's
154
+ (`@fennecstudio/meibo-js`) in snake_case.
155
+
156
+ | Method | Request | Scope | Returns |
157
+ | -------------------------------- | --------------------------------------- | ----------------------------------- | ---------------- |
158
+ | `read_settings()` | `GET /api/v1/directory` | any | `Settings` |
159
+ | `update_settings(update)` | `PUT /api/v1/directory` | `directory` | `Settings` |
160
+ | `list_entries(q=, page=)` | `GET /api/v1/directory/entries` | `entries:read` | `EntryList` |
161
+ | `create_entry(entry)` | `POST /api/v1/directory/entries` | `entries:write` | `EntryWritten` |
162
+ | `get_entry(entry_id)` | `GET /api/v1/directory/entries/{id}` | `entries:read` | `EntryDetail` |
163
+ | `update_entry(entry_id, update)` | `PUT /api/v1/directory/entries/{id}` | `entries:write` and/or `moderation` | `EntryWritten` |
164
+ | `delete_entry(entry_id)` | `DELETE /api/v1/directory/entries/{id}` | `moderation` | `EntryDeleted` |
165
+ | `list_moderation(page=)` | `GET /api/v1/directory/moderation` | `moderation` | `ModerationList` |
166
+ | `send_invites(emails)` | `POST /api/v1/directory/invites` | `invites` | `InvitesSent` |
167
+
168
+ A few things worth knowing:
169
+
170
+ - **An edit sends the whole entry.** `type` and `name` are always required, even
171
+ to change one field. A field left out keeps its value, but a list that is
172
+ sent is the whole list: send each parent, child or link you want to keep back
173
+ with its `id`, and a row without one is new.
174
+ - **`update_entry` also publishes, unpublishes and dismisses reports.**
175
+ `{"isPublished": ..., "dismissReports": ...}` alone needs `moderation` and
176
+ changes nothing else. Beside an edit it needs both scopes, and runs after the
177
+ edit.
178
+
179
+ ```python
180
+ meibo.update_entry(11, {"isPublished": True, "dismissReports": True})
181
+ ```
182
+
183
+ - **Lists are 48 to a page**, by name, and `page` counts from 1. `list_entries`
184
+ includes unpublished entries.
185
+ - **`send_invites` takes a string of addresses or a list**, joined into the one
186
+ string the API accepts. At most 20 addresses a request, and 200 invites per
187
+ directory in any 24 hours, the owner's own included.
188
+ - **An entry id is a positive whole number**, as an `int` or a string of
189
+ digits. Anything else raises `MeiboConfigError` before a request is made.
190
+
191
+ ## Errors
192
+
193
+ Every method raises on a non-2xx answer. The class comes from the status and
194
+ the refusal's `reason`, the word the API says to branch on. `err.message` is
195
+ the API's sentence for a person, and can change. Every error is a `MeiboError`,
196
+ with `status`, `reason` and the parsed `body`. When meibo itself refused,
197
+ `refusal` holds the refusal's fields.
198
+
199
+ | Class | Status | When | Carries |
200
+ | ------------------------------- | ------ | ------------------------------------------------------------------ | -------------------------- |
201
+ | `MeiboRequestError` | 400 | The body or a field failed a check, `reason` `photos` included | `refusal["field"]` |
202
+ | `MeiboDirectoryRequiredError` | 400 | The key reaches several directories and the call named none | `directories` |
203
+ | `MeiboAuthError` | 401 | No key, or one that is revoked or expired | |
204
+ | `MeiboScopeError` | 403 | The key lacks a scope the call needs | `scope` |
205
+ | `MeiboSuspendedError` | 403 | The owner's account is suspended | |
206
+ | `MeiboFrozenError` | 403 | The directory is past what the owner's plan allows | `plan`, `limit` |
207
+ | `MeiboForbiddenError` | 403 | Any other 403, and the parent of the three above | |
208
+ | `MeiboNotFoundError` | 404 | No entry with that id in this directory | |
209
+ | `MeiboDirectoryNotReachedError` | 404 | The key does not reach the directory named | |
210
+ | `MeiboRateLimitError` | 429 | The edge's rate limit, or the directory's invite cap | `remaining` (invites) |
211
+ | `MeiboServerError` | 5xx | Something failed on meibo's side | `sent`, `failed` (invites) |
212
+ | `MeiboConnectionError` | 0 | The request never completed: DNS, a reset connection, or a timeout | `cause` |
213
+ | `MeiboConfigError` | 0 | Arguments that cannot make a request: no key, or a bad entry id | |
214
+
215
+ A status with no class of its own — a `409` when publishing would pass the
216
+ plan's entry limit (`reason` `entry_limit`), a `413` for a logo that is too
217
+ large — arrives as `MeiboError` with its `reason` and `refusal`.
218
+
219
+ ```python
220
+ from meibo import MeiboError, MeiboScopeError
221
+
222
+ try:
223
+ meibo.list_entries()
224
+ except MeiboScopeError as err:
225
+ print(f"Ask the owner for a key with {err.scope}.")
226
+ except MeiboError as err:
227
+ if err.reason != "entry_limit":
228
+ raise
229
+ print(f"The plan publishes at most {err.refusal['limit']} entries.")
230
+ ```
231
+
232
+ **A suspended owner's key, and a frozen directory's, keep reading and
233
+ withdrawing.** Reads, unpublishing an entry and deleting one are still served.
234
+ Every other write raises `MeiboSuspendedError` or `MeiboFrozenError`.
235
+
236
+ **What a `send_invites` error says about delivery depends on the error.**
237
+
238
+ - A refusal the API answered with — `MeiboRequestError`, `MeiboAuthError`,
239
+ `MeiboForbiddenError` and its subclasses, `MeiboRateLimitError` — emailed
240
+ nothing.
241
+ - A `MeiboServerError` with a non-empty `sent` emailed those addresses and not
242
+ `failed`. One without them carries no account of delivery.
243
+ - A `MeiboConnectionError` says **nothing about delivery**. A timeout, a reset
244
+ or a response lost on its way back can come after meibo already emailed some
245
+ or all of the addresses. The SDK does not retry, and nor should you without
246
+ checking: a blind retry can email the same people twice. Treat the
247
+ addresses as possibly invited, and re-send only the ones you can confirm
248
+ were not.
249
+
250
+ ### Rate limits
251
+
252
+ The edge allows 300 requests per 5 minutes from one IP address, and 600 per 5
253
+ minutes with one key. Past either, a call raises `MeiboRateLimitError` with no
254
+ `remaining`. Back off and retry.
255
+
256
+ ## Options
257
+
258
+ ```python
259
+ Meibo(
260
+ api_key="your key", # required
261
+ directory="maple", # default directory slug, overridden per call
262
+ base_url="https://api.meibo.io", # the default
263
+ timeout=30.0, # seconds per request, the default; None or 0 turns it off
264
+ transport=None, # an httpx transport, for tests, proxies or retries
265
+ )
266
+ ```
267
+
268
+ `timeout` is in **seconds**, where the JavaScript SDK's `timeoutMs` is
269
+ milliseconds. The key is sent as `Authorization: Bearer <key>`. One given with a
270
+ `Bearer ` prefix already is sent with just the one.
271
+
272
+ ## For AI agents
273
+
274
+ meibo also serves this API as an MCP server, at
275
+ `https://api.meibo.io/api/v1/directory/mcp`, for an assistant that speaks MCP
276
+ rather than running code. It takes the same key and the same scopes.
277
+
278
+ ## Something did not work?
279
+
280
+ Email support@fennec.studio with the method and path, the status, and the
281
+ `error` and `reason` you got, and what you expected. Leave out the key and
282
+ anything an entry holds.
283
+
284
+ ## License
285
+
286
+ ISC
meibo-1.0.0/README.md ADDED
@@ -0,0 +1,256 @@
1
+ # meibo
2
+
3
+ Python client for the [meibo](https://meibo.io) API. Read and change a school or
4
+ club directory — its settings, its families and staff, its moderation queue and
5
+ its invites — through a key the directory's owner hands you.
6
+
7
+ ```bash
8
+ pip install meibo
9
+ ```
10
+
11
+ Python 3.10+. One dependency, [httpx](https://www.python-httpx.org), which is what
12
+ gives you a sync and an async client from the same package. The full API
13
+ reference is at [meibo.io/developers](https://meibo.io/developers/).
14
+
15
+ ## Quickstart
16
+
17
+ ```python
18
+ import os
19
+ from meibo import Meibo
20
+
21
+ meibo = Meibo(api_key=os.environ["MEIBO_API_KEY"], directory="maple")
22
+
23
+ settings = meibo.read_settings()
24
+ print(settings["name"], settings["scopes"])
25
+
26
+ written = meibo.create_entry({
27
+ "type": "family",
28
+ "name": "The Parks",
29
+ "parents": [{"name": "Min-jun Park", "email": "minjun@example.com", "phoneNumber": "555-0142"}],
30
+ "children": [{"name": "Seo-yeon", "teacher": "Mr. Chen"}],
31
+ })
32
+ print(written["id"], written["isPublished"])
33
+ ```
34
+
35
+ Every method answers the API's JSON as a `dict`, unwrapped from its
36
+ `{"success": true, "data": ...}` envelope and otherwise untouched, so its keys
37
+ are the reference's camelCase ones. The `TypedDict`s in `meibo.types` describe
38
+ each shape under the reference's own schema names, so a type checker knows
39
+ `written["isPublished"]` is a `bool`. A request body is a plain `dict` of the
40
+ same shape.
41
+
42
+ ## Async
43
+
44
+ `AsyncMeibo` has the same methods with the same arguments, awaited:
45
+
46
+ ```python
47
+ from meibo import AsyncMeibo
48
+
49
+ async with AsyncMeibo(api_key=key, directory="maple") as meibo:
50
+ page = await meibo.list_entries(q="okafor")
51
+ ```
52
+
53
+ Both clients open their connection pool on the first request. Close it when
54
+ you are done — `with Meibo(...) as meibo:`, or `meibo.close()` /
55
+ `await meibo.aclose()` — or keep one long-lived client rather than building one
56
+ per request.
57
+
58
+ ## Keys
59
+
60
+ The directory's owner makes a key on their account page at
61
+ [meibo.io/account](https://meibo.io/account/), and chooses its scopes there. It
62
+ is shown once. meibo keeps only a hash of it, so a lost key is revoked and
63
+ replaced, never recovered.
64
+
65
+ A key acts as the owner, for every directory the owner has, and follows the
66
+ owner's rules. Keep it on a server: anyone holding it can do what its scopes
67
+ allow.
68
+
69
+ Every call a key makes is logged against the directory it reached, with its
70
+ method, route and status, refusals included. The owner can read that log for 90
71
+ days.
72
+
73
+ ### Scopes
74
+
75
+ | Scope | Allows |
76
+ | --------------- | ------------------------------------------------------------------------------------------------------------ |
77
+ | `directory` | Changing the directory's name, preset, groups and logo. |
78
+ | `entries:write` | Adding entries and editing them. |
79
+ | `moderation` | Reading the moderation queue, publishing and unpublishing entries, dismissing reports, and deleting entries. |
80
+ | `invites` | Emailing families the directory's address, within its invite cap. It lets nobody in. |
81
+ | `entries:read` | Reading entries in full, contacts and children's names included. |
82
+
83
+ **`entries:read` is off unless the owner grants it.** When they do, the
84
+ dashboard tells them that what the key reads goes to the assistant's AI
85
+ provider. A key without it can still add, edit, publish and delete entries, but
86
+ what those writes answer is an entry's `id` and `isPublished`, and nothing of
87
+ what is in it. `list_moderation` without it answers a summary of each entry,
88
+ without contacts or children's names.
89
+
90
+ `read_settings` is open to any key and answers the key's own `scopes`, so call
91
+ it to find out what a key may do before trying.
92
+
93
+ ### Photos are never sent
94
+
95
+ The API serves no photos, and a key cannot send one. An entry carries
96
+ `hasPhoto` wherever the dashboard shows a photo: on the entry, and on each
97
+ parent and child. The input types here have no `photoKey`, and a body that
98
+ carries one anyway is refused with `reason` `photos`. Editing an entry keeps the
99
+ photos it already has.
100
+
101
+ ## Choosing a directory
102
+
103
+ When the owner has one directory, a key reaches it and nothing needs naming.
104
+ When they have more than one, name the directory by its slug, the last part of
105
+ its address: once on the client as `directory`, or on any call as its
106
+ `directory` argument, which wins.
107
+
108
+ ```python
109
+ from meibo import Meibo, MeiboDirectoryRequiredError
110
+
111
+ meibo = Meibo(api_key=key)
112
+
113
+ try:
114
+ meibo.read_settings()
115
+ except MeiboDirectoryRequiredError as err:
116
+ print("Pick one of:", err.directories) # ['maple', 'oak']
117
+ meibo.read_settings(directory=err.directories[0])
118
+ ```
119
+
120
+ ## Methods
121
+
122
+ Each method takes a keyword-only `directory=`, and returns the operation's
123
+ answer, already unwrapped. The names are the JavaScript SDK's
124
+ (`@fennecstudio/meibo-js`) in snake_case.
125
+
126
+ | Method | Request | Scope | Returns |
127
+ | -------------------------------- | --------------------------------------- | ----------------------------------- | ---------------- |
128
+ | `read_settings()` | `GET /api/v1/directory` | any | `Settings` |
129
+ | `update_settings(update)` | `PUT /api/v1/directory` | `directory` | `Settings` |
130
+ | `list_entries(q=, page=)` | `GET /api/v1/directory/entries` | `entries:read` | `EntryList` |
131
+ | `create_entry(entry)` | `POST /api/v1/directory/entries` | `entries:write` | `EntryWritten` |
132
+ | `get_entry(entry_id)` | `GET /api/v1/directory/entries/{id}` | `entries:read` | `EntryDetail` |
133
+ | `update_entry(entry_id, update)` | `PUT /api/v1/directory/entries/{id}` | `entries:write` and/or `moderation` | `EntryWritten` |
134
+ | `delete_entry(entry_id)` | `DELETE /api/v1/directory/entries/{id}` | `moderation` | `EntryDeleted` |
135
+ | `list_moderation(page=)` | `GET /api/v1/directory/moderation` | `moderation` | `ModerationList` |
136
+ | `send_invites(emails)` | `POST /api/v1/directory/invites` | `invites` | `InvitesSent` |
137
+
138
+ A few things worth knowing:
139
+
140
+ - **An edit sends the whole entry.** `type` and `name` are always required, even
141
+ to change one field. A field left out keeps its value, but a list that is
142
+ sent is the whole list: send each parent, child or link you want to keep back
143
+ with its `id`, and a row without one is new.
144
+ - **`update_entry` also publishes, unpublishes and dismisses reports.**
145
+ `{"isPublished": ..., "dismissReports": ...}` alone needs `moderation` and
146
+ changes nothing else. Beside an edit it needs both scopes, and runs after the
147
+ edit.
148
+
149
+ ```python
150
+ meibo.update_entry(11, {"isPublished": True, "dismissReports": True})
151
+ ```
152
+
153
+ - **Lists are 48 to a page**, by name, and `page` counts from 1. `list_entries`
154
+ includes unpublished entries.
155
+ - **`send_invites` takes a string of addresses or a list**, joined into the one
156
+ string the API accepts. At most 20 addresses a request, and 200 invites per
157
+ directory in any 24 hours, the owner's own included.
158
+ - **An entry id is a positive whole number**, as an `int` or a string of
159
+ digits. Anything else raises `MeiboConfigError` before a request is made.
160
+
161
+ ## Errors
162
+
163
+ Every method raises on a non-2xx answer. The class comes from the status and
164
+ the refusal's `reason`, the word the API says to branch on. `err.message` is
165
+ the API's sentence for a person, and can change. Every error is a `MeiboError`,
166
+ with `status`, `reason` and the parsed `body`. When meibo itself refused,
167
+ `refusal` holds the refusal's fields.
168
+
169
+ | Class | Status | When | Carries |
170
+ | ------------------------------- | ------ | ------------------------------------------------------------------ | -------------------------- |
171
+ | `MeiboRequestError` | 400 | The body or a field failed a check, `reason` `photos` included | `refusal["field"]` |
172
+ | `MeiboDirectoryRequiredError` | 400 | The key reaches several directories and the call named none | `directories` |
173
+ | `MeiboAuthError` | 401 | No key, or one that is revoked or expired | |
174
+ | `MeiboScopeError` | 403 | The key lacks a scope the call needs | `scope` |
175
+ | `MeiboSuspendedError` | 403 | The owner's account is suspended | |
176
+ | `MeiboFrozenError` | 403 | The directory is past what the owner's plan allows | `plan`, `limit` |
177
+ | `MeiboForbiddenError` | 403 | Any other 403, and the parent of the three above | |
178
+ | `MeiboNotFoundError` | 404 | No entry with that id in this directory | |
179
+ | `MeiboDirectoryNotReachedError` | 404 | The key does not reach the directory named | |
180
+ | `MeiboRateLimitError` | 429 | The edge's rate limit, or the directory's invite cap | `remaining` (invites) |
181
+ | `MeiboServerError` | 5xx | Something failed on meibo's side | `sent`, `failed` (invites) |
182
+ | `MeiboConnectionError` | 0 | The request never completed: DNS, a reset connection, or a timeout | `cause` |
183
+ | `MeiboConfigError` | 0 | Arguments that cannot make a request: no key, or a bad entry id | |
184
+
185
+ A status with no class of its own — a `409` when publishing would pass the
186
+ plan's entry limit (`reason` `entry_limit`), a `413` for a logo that is too
187
+ large — arrives as `MeiboError` with its `reason` and `refusal`.
188
+
189
+ ```python
190
+ from meibo import MeiboError, MeiboScopeError
191
+
192
+ try:
193
+ meibo.list_entries()
194
+ except MeiboScopeError as err:
195
+ print(f"Ask the owner for a key with {err.scope}.")
196
+ except MeiboError as err:
197
+ if err.reason != "entry_limit":
198
+ raise
199
+ print(f"The plan publishes at most {err.refusal['limit']} entries.")
200
+ ```
201
+
202
+ **A suspended owner's key, and a frozen directory's, keep reading and
203
+ withdrawing.** Reads, unpublishing an entry and deleting one are still served.
204
+ Every other write raises `MeiboSuspendedError` or `MeiboFrozenError`.
205
+
206
+ **What a `send_invites` error says about delivery depends on the error.**
207
+
208
+ - A refusal the API answered with — `MeiboRequestError`, `MeiboAuthError`,
209
+ `MeiboForbiddenError` and its subclasses, `MeiboRateLimitError` — emailed
210
+ nothing.
211
+ - A `MeiboServerError` with a non-empty `sent` emailed those addresses and not
212
+ `failed`. One without them carries no account of delivery.
213
+ - A `MeiboConnectionError` says **nothing about delivery**. A timeout, a reset
214
+ or a response lost on its way back can come after meibo already emailed some
215
+ or all of the addresses. The SDK does not retry, and nor should you without
216
+ checking: a blind retry can email the same people twice. Treat the
217
+ addresses as possibly invited, and re-send only the ones you can confirm
218
+ were not.
219
+
220
+ ### Rate limits
221
+
222
+ The edge allows 300 requests per 5 minutes from one IP address, and 600 per 5
223
+ minutes with one key. Past either, a call raises `MeiboRateLimitError` with no
224
+ `remaining`. Back off and retry.
225
+
226
+ ## Options
227
+
228
+ ```python
229
+ Meibo(
230
+ api_key="your key", # required
231
+ directory="maple", # default directory slug, overridden per call
232
+ base_url="https://api.meibo.io", # the default
233
+ timeout=30.0, # seconds per request, the default; None or 0 turns it off
234
+ transport=None, # an httpx transport, for tests, proxies or retries
235
+ )
236
+ ```
237
+
238
+ `timeout` is in **seconds**, where the JavaScript SDK's `timeoutMs` is
239
+ milliseconds. The key is sent as `Authorization: Bearer <key>`. One given with a
240
+ `Bearer ` prefix already is sent with just the one.
241
+
242
+ ## For AI agents
243
+
244
+ meibo also serves this API as an MCP server, at
245
+ `https://api.meibo.io/api/v1/directory/mcp`, for an assistant that speaks MCP
246
+ rather than running code. It takes the same key and the same scopes.
247
+
248
+ ## Something did not work?
249
+
250
+ Email support@fennec.studio with the method and path, the status, and the
251
+ `error` and `reason` you got, and what you expected. Leave out the key and
252
+ anything an entry holds.
253
+
254
+ ## License
255
+
256
+ ISC
@@ -0,0 +1,48 @@
1
+ import pytest
2
+
3
+ from helpers import FLAVOURS, FakeApi, Reply, envelope, invoke
4
+
5
+ FAMILY = {
6
+ "type": "family",
7
+ "name": "The Parks",
8
+ "parents": [{"name": "Min-jun Park", "email": "minjun@example.com", "phoneNumber": "555-0142"}],
9
+ "children": [{"name": "Seo-yeon", "teacher": "Mr. Chen"}],
10
+ }
11
+
12
+
13
+ @pytest.mark.parametrize("flavour", FLAVOURS)
14
+ def test_posts_the_entry_to_entries_and_unwraps_what_was_written(flavour):
15
+ api = FakeApi(Reply(status=201, body=envelope({"id": 12, "isPublished": False})))
16
+
17
+ written = invoke(flavour, api, lambda meibo: meibo.create_entry(FAMILY))
18
+
19
+ assert written == {"id": 12, "isPublished": False}
20
+ assert api.sent.method == "POST"
21
+ assert api.sent.path == "/api/v1/directory/entries"
22
+ assert api.sent.query == {}
23
+ assert api.sent.body == FAMILY
24
+
25
+
26
+ @pytest.mark.parametrize("flavour", FLAVOURS)
27
+ def test_names_the_directory_the_call_overrides_with(flavour):
28
+ api = FakeApi(Reply(status=201, body=envelope({"id": 12, "isPublished": True})))
29
+
30
+ invoke(
31
+ flavour,
32
+ api,
33
+ lambda meibo: meibo.create_entry({"type": "staff", "name": "Ms. Rivera"}, directory="maple"),
34
+ directory="oak",
35
+ )
36
+
37
+ assert api.sent.query == {"directory": "maple"}
38
+ assert api.sent.body == {"type": "staff", "name": "Ms. Rivera"}
39
+
40
+
41
+ @pytest.mark.parametrize("flavour", FLAVOURS)
42
+ def test_sends_non_ascii_names_as_utf8_rather_than_escapes(flavour):
43
+ api = FakeApi(Reply(status=201, body=envelope({"id": 12, "isPublished": True})))
44
+
45
+ invoke(flavour, api, lambda meibo: meibo.create_entry({"type": "individual", "name": "佐藤 花子"}))
46
+
47
+ assert api.sent.body == {"type": "individual", "name": "佐藤 花子"}
48
+ assert api.sent.raw == '{"type":"individual","name":"佐藤 花子"}'.encode("utf-8")
@@ -0,0 +1,55 @@
1
+ import pytest
2
+
3
+ from helpers import FLAVOURS, FakeApi, Reply, envelope, invoke
4
+ from meibo import MeiboConfigError, MeiboScopeError
5
+
6
+
7
+ @pytest.mark.parametrize("flavour", FLAVOURS)
8
+ def test_deletes_the_entry_and_unwraps_its_id(flavour):
9
+ api = FakeApi(Reply(body=envelope({"id": 3})))
10
+
11
+ assert invoke(flavour, api, lambda meibo: meibo.delete_entry(3)) == {"id": 3}
12
+
13
+ assert api.sent.method == "DELETE"
14
+ assert api.sent.path == "/api/v1/directory/entries/3"
15
+ assert api.sent.query == {}
16
+ assert api.sent.body is None
17
+ assert "content-type" not in api.sent.headers
18
+
19
+
20
+ @pytest.mark.parametrize("flavour", FLAVOURS)
21
+ def test_names_the_clients_directory(flavour):
22
+ api = FakeApi(Reply(body=envelope({"id": 3})))
23
+
24
+ invoke(flavour, api, lambda meibo: meibo.delete_entry(3), directory="maple")
25
+
26
+ assert api.sent.query == {"directory": "maple"}
27
+
28
+
29
+ @pytest.mark.parametrize("flavour", FLAVOURS)
30
+ def test_refuses_an_id_that_is_not_a_positive_whole_number_before_any_request(flavour):
31
+ api = FakeApi()
32
+
33
+ with pytest.raises(MeiboConfigError):
34
+ invoke(flavour, api, lambda meibo: meibo.delete_entry("3/../4"))
35
+
36
+ assert api.calls == []
37
+
38
+
39
+ @pytest.mark.parametrize("flavour", FLAVOURS)
40
+ def test_raises_a_scope_error_for_a_key_without_moderation(flavour):
41
+ api = FakeApi(
42
+ Reply(
43
+ status=403,
44
+ body={
45
+ "error": "This API key does not have the moderation scope.",
46
+ "reason": "scope",
47
+ "scope": "moderation",
48
+ },
49
+ )
50
+ )
51
+
52
+ with pytest.raises(MeiboScopeError) as excinfo:
53
+ invoke(flavour, api, lambda meibo: meibo.delete_entry(3))
54
+
55
+ assert excinfo.value.scope == "moderation"