Metadata-Version: 2.5
Name: meibo
Version: 1.0.1
Summary: SDK for meibo's directory API — school and club directories, through a key their owner hands you
Project-URL: Homepage, https://meibo.io
Project-URL: Documentation, https://meibo.io/developers/
Project-URL: Repository, https://github.com/fennecstudio/platform
Project-URL: Issues, https://github.com/fennecstudio/platform/issues
Author: Fennec Studio
License: ISC
Keywords: club,directory,meibo,roster,school,sdk
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: ISC License (ISCL)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx<1,>=0.23
Provides-Extra: dev
Requires-Dist: mypy>=1.8; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
Requires-Dist: pytest>=7.4; extra == 'dev'
Description-Content-Type: text/markdown

# meibo

Python client for the [meibo](https://meibo.io) API. Read and change a school or
club directory — its settings, its families and staff, its moderation queue and
its invites — through a key the directory's owner hands you.

```bash
pip install meibo
```

Python 3.10+. One dependency, [httpx](https://www.python-httpx.org), which is what
gives you a sync and an async client from the same package. The full API
reference is at [meibo.io/developers](https://meibo.io/developers/).

## Quickstart

```python
import os
from meibo import Meibo

meibo = Meibo(api_key=os.environ["MEIBO_API_KEY"], directory="maple")

settings = meibo.read_settings()
print(settings["name"], settings["scopes"])

written = meibo.create_entry({
    "type": "family",
    "name": "The Parks",
    "parents": [{"name": "Min-jun Park", "email": "minjun@example.com", "phoneNumber": "555-0142"}],
    "children": [{"name": "Seo-yeon", "teacher": "Mr. Chen"}],
})
print(written["id"], written["isPublished"])
```

Every method answers the API's JSON as a `dict`, unwrapped from its
`{"success": true, "data": ...}` envelope and otherwise untouched, so its keys
are the reference's camelCase ones. The `TypedDict`s in `meibo.types` describe
each shape under the reference's own schema names, so a type checker knows
`written["isPublished"]` is a `bool`. A request body is a plain `dict` of the
same shape.

## Async

`AsyncMeibo` has the same methods with the same arguments, awaited:

```python
from meibo import AsyncMeibo

async with AsyncMeibo(api_key=key, directory="maple") as meibo:
    page = await meibo.list_entries(q="okafor")
```

Both clients open their connection pool on the first request. Close it when
you are done — `with Meibo(...) as meibo:`, or `meibo.close()` /
`await meibo.aclose()` — or keep one long-lived client rather than building one
per request.

## Keys

The directory's owner makes a key on their account page at
[meibo.io/account](https://meibo.io/account/), and chooses its scopes there. It
is shown once. meibo keeps only a hash of it, so a lost key is revoked and
replaced, never recovered.

A key acts as the owner, for every directory the owner has, and follows the
owner's rules. Keep it on a server: anyone holding it can do what its scopes
allow.

Every call a key makes is logged against the directory it reached, with its
method, route and status, refusals included. The owner can read that log for 90
days.

### Scopes

| Scope           | Allows                                                                                                       |
| --------------- | ------------------------------------------------------------------------------------------------------------ |
| `directory`     | Changing the directory's name, preset, groups and logo.                                                      |
| `entries:write` | Adding entries and editing them.                                                                             |
| `moderation`    | Reading the moderation queue, publishing and unpublishing entries, dismissing reports, and deleting entries. |
| `invites`       | Emailing families the directory's address, within its invite cap. It lets nobody in.                         |
| `entries:read`  | Reading entries in full, contacts and children's names included.                                             |

**`entries:read` is off unless the owner grants it.** When they do, the
dashboard tells them that what the key reads goes to the assistant's AI
provider. A key without it can still add, edit, publish and delete entries, but
what those writes answer is an entry's `id` and `isPublished`, and nothing of
what is in it. `list_moderation` without it answers a summary of each entry,
without contacts or children's names.

`read_settings` is open to any key and answers the key's own `scopes`, so call
it to find out what a key may do before trying.

### Photos are never sent

The API serves no photos, and a key cannot send one. An entry carries
`hasPhoto` wherever the dashboard shows a photo: on the entry, and on each
parent and child. The input types here have no `photoKey`, and a body that
carries one anyway is refused with `reason` `photos`. Editing an entry keeps the
photos it already has.

## Choosing a directory

When the owner has one directory, a key reaches it and nothing needs naming.
When they have more than one, name the directory by its slug, the last part of
its address: once on the client as `directory`, or on any call as its
`directory` argument, which wins.

```python
from meibo import Meibo, MeiboDirectoryRequiredError

meibo = Meibo(api_key=key)

try:
    meibo.read_settings()
except MeiboDirectoryRequiredError as err:
    print("Pick one of:", err.directories)  # ['maple', 'oak']
    meibo.read_settings(directory=err.directories[0])
```

## Methods

Each method takes a keyword-only `directory=`, and returns the operation's
answer, already unwrapped. The names are the JavaScript SDK's
(`@fennecstudio/meibo-js`) in snake_case.

| Method                           | Request                                 | Scope                               | Returns          |
| -------------------------------- | --------------------------------------- | ----------------------------------- | ---------------- |
| `read_settings()`                | `GET /api/v1/directory`                 | any                                 | `Settings`       |
| `update_settings(update)`        | `PUT /api/v1/directory`                 | `directory`                         | `Settings`       |
| `list_entries(q=, page=)`        | `GET /api/v1/directory/entries`         | `entries:read`                      | `EntryList`      |
| `create_entry(entry)`            | `POST /api/v1/directory/entries`        | `entries:write`                     | `EntryWritten`   |
| `get_entry(entry_id)`            | `GET /api/v1/directory/entries/{id}`    | `entries:read`                      | `EntryDetail`    |
| `update_entry(entry_id, update)` | `PUT /api/v1/directory/entries/{id}`    | `entries:write` and/or `moderation` | `EntryWritten`   |
| `delete_entry(entry_id)`         | `DELETE /api/v1/directory/entries/{id}` | `moderation`                        | `EntryDeleted`   |
| `list_moderation(page=)`         | `GET /api/v1/directory/moderation`      | `moderation`                        | `ModerationList` |
| `send_invites(emails)`           | `POST /api/v1/directory/invites`        | `invites`                           | `InvitesSent`    |

A few things worth knowing:

- **An edit sends the whole entry.** `type` and `name` are always required, even
  to change one field. A field left out keeps its value, but a list that is
  sent is the whole list: send each parent, child or link you want to keep back
  with its `id`, and a row without one is new.
- **`update_entry` also publishes, unpublishes and dismisses reports.**
  `{"isPublished": ..., "dismissReports": ...}` alone needs `moderation` and
  changes nothing else. Beside an edit it needs both scopes, and runs after the
  edit.

  ```python
  meibo.update_entry(11, {"isPublished": True, "dismissReports": True})
  ```

- **Lists are 48 to a page**, by name, and `page` counts from 1. `list_entries`
  includes unpublished entries.
- **`send_invites` takes a string of addresses or a list**, joined into the one
  string the API accepts. At most 20 addresses a request, and 200 invites per
  directory in any 24 hours, the owner's own included.
- **An entry id is a positive whole number**, as an `int` or a string of
  digits. Anything else raises `MeiboConfigError` before a request is made.

## Errors

Every method raises on a non-2xx answer. The class comes from the status and
the refusal's `reason`, the word the API says to branch on. `err.message` is
the API's sentence for a person, and can change. Every error is a `MeiboError`,
with `status`, `reason` and the parsed `body`. When meibo itself refused,
`refusal` holds the refusal's fields.

| Class                           | Status | When                                                               | Carries                    |
| ------------------------------- | ------ | ------------------------------------------------------------------ | -------------------------- |
| `MeiboRequestError`             | 400    | The body or a field failed a check, `reason` `photos` included     | `refusal["field"]`         |
| `MeiboDirectoryRequiredError`   | 400    | The key reaches several directories and the call named none        | `directories`              |
| `MeiboAuthError`                | 401    | No key, or one that is revoked or expired                          |                            |
| `MeiboScopeError`               | 403    | The key lacks a scope the call needs                               | `scope`                    |
| `MeiboSuspendedError`           | 403    | The owner's account is suspended                                   |                            |
| `MeiboFrozenError`              | 403    | The directory is past what the owner's plan allows                 | `plan`, `limit`            |
| `MeiboForbiddenError`           | 403    | Any other 403, and the parent of the three above                   |                            |
| `MeiboNotFoundError`            | 404    | No entry with that id in this directory                            |                            |
| `MeiboDirectoryNotReachedError` | 404    | The key does not reach the directory named                         |                            |
| `MeiboRateLimitError`           | 429    | The edge's rate limit, or the directory's invite cap               | `remaining` (invites)      |
| `MeiboServerError`              | 5xx    | Something failed on meibo's side                                   | `sent`, `failed` (invites) |
| `MeiboConnectionError`          | 0      | The request never completed: DNS, a reset connection, or a timeout | `cause`                    |
| `MeiboConfigError`              | 0      | Arguments that cannot make a request: no key, or a bad entry id    |                            |

A status with no class of its own — a `409` when publishing would pass the
plan's entry limit (`reason` `entry_limit`), a `413` for a logo that is too
large — arrives as `MeiboError` with its `reason` and `refusal`.

```python
from meibo import MeiboError, MeiboScopeError

try:
    meibo.list_entries()
except MeiboScopeError as err:
    print(f"Ask the owner for a key with {err.scope}.")
except MeiboError as err:
    if err.reason != "entry_limit":
        raise
    print(f"The plan publishes at most {err.refusal['limit']} entries.")
```

**A suspended owner's key, and a frozen directory's, keep reading and
withdrawing.** Reads, unpublishing an entry and deleting one are still served.
Every other write raises `MeiboSuspendedError` or `MeiboFrozenError`.

**What a `send_invites` error says about delivery depends on the error.**

- A refusal the API answered with — `MeiboRequestError`, `MeiboAuthError`,
  `MeiboForbiddenError` and its subclasses, `MeiboRateLimitError` — emailed
  nothing.
- A `MeiboServerError` with a non-empty `sent` emailed those addresses and not
  `failed`. One without them carries no account of delivery.
- A `MeiboConnectionError` says **nothing about delivery**. A timeout, a reset
  or a response lost on its way back can come after meibo already emailed some
  or all of the addresses. The SDK does not retry, and nor should you without
  checking: a blind retry can email the same people twice. Treat the
  addresses as possibly invited, and re-send only the ones you can confirm
  were not.

### Rate limits

The edge allows 300 requests per 5 minutes from one IP address, and 600 per 5
minutes with one key. Past either, a call raises `MeiboRateLimitError` with no
`remaining`. Back off and retry.

## Options

```python
Meibo(
    api_key="your key",              # required
    directory="maple",               # default directory slug, overridden per call
    base_url="https://api.meibo.io", # the default
    timeout=30.0,                    # seconds per request, the default; None or 0 turns it off
    transport=None,                  # an httpx transport, for tests, proxies or retries
)
```

`timeout` is in **seconds**, where the JavaScript SDK's `timeoutMs` is
milliseconds. The key is sent as `Authorization: Bearer <key>`. One given with a
`Bearer ` prefix already is sent with just the one.

## For AI agents

meibo also serves this API as an MCP server, at
`https://api.meibo.io/api/v1/directory/mcp`, for an assistant that speaks MCP
rather than running code. It takes the same key and the same scopes.

## Something did not work?

Email support@fennec.studio with the method and path, the status, and the
`error` and `reason` you got, and what you expected. Leave out the key and
anything an entry holds.

## License

ISC
