Skip to content

Commit 1fec8f8

Browse files
author
Peter Sprygada
committed
feat: add TOML support to serdes and improve docs
- Add TOML read support via stdlib tomllib (Python 3.11+) with tomli backport for Python 3.10 - Add TOML write support via optional tomli-w, guarded by TOML_WRITE_AVAILABLE flag - Extend loads() and dumps() to accept 'toml' as a format hint/type - Reject top-level lists in toml_dumps() with a clear ValidationError message - Rewrite all serdes docstrings with full Args/Returns/Raises sections and format constraints - Update docs/development.md with correct Python version, full project structure, and Optional Dependencies table - Add tomli and tomli_w to mypy ignore_missing_imports overrides
1 parent c66fa45 commit 1fec8f8

4 files changed

Lines changed: 258 additions & 32 deletions

File tree

docs/development.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,49 @@ asyncgateway/
8080
│ ├── client.py # Client class with service/resource discovery
8181
│ ├── exceptions.py # Exception hierarchy (AsyncGatewayError, ValidationError)
8282
│ ├── logging.py # Logging with sensitive data filtering
83-
│ ├── serdes.py # JSON/YAML serialization
83+
│ ├── serdes.py # JSON / YAML / TOML serialization utilities
8484
│ ├── services/ # 23 thin async wrappers, one per IAG API tag group
8585
│ └── resources/ # 22 declarative resource abstractions
8686
├── tests/ # Test files (mock ipsdk, no live IAG needed)
8787
├── docs/ # Documentation
8888
└── pyproject.toml # Project configuration and tool settings
8989
```
9090

91+
## Optional Dependencies
92+
93+
The core library requires only `ipsdk`. Additional serialization formats can
94+
be unlocked by installing optional packages:
95+
96+
| Format | Operation | Package | Python version |
97+
|--------|-----------|---------|----------------|
98+
| YAML | read & write | `PyYAML` | any |
99+
| TOML | read | *(stdlib `tomllib`)* | 3.11+ |
100+
| TOML | read | `tomli` | 3.10 only |
101+
| TOML | write | `tomli-w` | any |
102+
103+
Install a single optional format:
104+
105+
```bash
106+
uv add PyYAML # YAML support
107+
uv add tomli # TOML read on Python 3.10
108+
uv add tomli-w # TOML write (any version)
109+
```
110+
111+
Install all optional serialization extras at once:
112+
113+
```bash
114+
uv add PyYAML tomli-w # tomli only needed on Python 3.10
115+
```
116+
117+
You can inspect runtime availability from Python:
118+
119+
```python
120+
from asyncgateway.serdes import YAML_AVAILABLE, TOML_AVAILABLE, TOML_WRITE_AVAILABLE
121+
```
122+
123+
Calling a function whose dependency is absent raises `ValidationError` (not
124+
`ImportError`), so callers do not need to guard imports.
125+
91126
## Development Notes
92127

93128
- Services and resources are filesystem-discovered at client init. Adding a file with a `Service` or `Resource` class and a `name` attribute is sufficient for registration — no other wiring required.
@@ -114,3 +149,4 @@ asyncgateway/
114149
- For test failures, run with `-v` for more detailed output.
115150
- If tests mock `os.listdir`, note that `Client.__init__` calls it **twice** — once for `services/` and once for `resources/`. Use `side_effect=[service_files, resource_files]`.
116151
- YAML support is optional. If `PyYAML` is not installed, YAML paths raise `ValidationError` rather than `ImportError`.
152+
- TOML read support is optional on Python 3.10 (install `tomli`); on 3.11+ it uses the stdlib `tomllib`. TOML write always requires `tomli-w`.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ python_version = "3.11"
118118
warn_unused_configs = true
119119

120120
[[tool.mypy.overrides]]
121-
module = ["ipsdk.*", "yaml"]
121+
module = ["ipsdk.*", "yaml", "tomli", "tomli_w"]
122122
ignore_missing_imports = true
123123

124124
[tool.bandit]

0 commit comments

Comments
 (0)