|
| 1 | +# Project overview |
| 2 | + |
| 3 | +This is the official Python SDK for [Deno Sandboxes](https://deno.com/deploy/sandboxes) (`deno-sandbox` on PyPI). It provides programmatic access to create and manage sandboxes, execute code, manage filesystems, volumes, apps, and deployments. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +- **Async-first**: All I/O is implemented as async code first. The sync API wraps it via `AsyncBridge` (in `bridge.py`), which runs a separate event loop in a background thread. |
| 8 | +- **Class naming**: Async classes are prefixed with `Async` (e.g., `AsyncDenoDeploy`, `AsyncSandbox`, `AsyncSandboxFs`). Sync wrappers drop the prefix (`DenoDeploy`, `Sandbox`, `SandboxFs`). |
| 9 | +- **Data models**: Use `TypedDict` for all data models. Do NOT use dataclasses or Pydantic. |
| 10 | +- **HTTP**: Uses `httpx.AsyncClient`. Do NOT introduce `requests` or `aiohttp`. |
| 11 | +- **WebSocket**: Uses `websockets`. Do NOT introduce other WS libraries. |
| 12 | +- **Source code**: `src/deno_sandbox/` |
| 13 | +- **Public exports**: `src/deno_sandbox/__init__.py` |
| 14 | + |
| 15 | +## Key files |
| 16 | + |
| 17 | +- `bridge.py` — `AsyncBridge` that powers the sync API |
| 18 | +- `sandbox.py` — Sandbox creation and management |
| 19 | +- `fs.py` — Filesystem operations |
| 20 | +- `process.py` — Child process management |
| 21 | +- `rpc.py` — JSON-RPC 2.0 over WebSocket |
| 22 | +- `console.py` — HTTP client for Console API |
| 23 | +- `apps.py` — App management |
| 24 | +- `revisions.py` — Deployment revisions |
| 25 | +- `errors.py` — Custom exception classes |
| 26 | +- `options.py` — Configuration |
| 27 | + |
| 28 | +# API design |
| 29 | + |
| 30 | +- MUST design pythonic APIs: snake_case, keyword arguments, no unnecessary classes. |
| 31 | +- MUST be consistent with the existing API in this codebase. When unsure, read existing code first and ask the user. |
| 32 | +- MUST NOT make breaking changes. If a breaking change would improve consistency, ask the user for permission first. |
| 33 | +- MUST add tests for every bug fix and new feature. Place tests in `tests/test_<module>.py`. |
| 34 | +- MUST implement every new feature for the async API first, then ensure the sync wrapper exposes it too. MUST add tests for both sync and async variants. |
| 35 | + |
| 36 | +# Development |
| 37 | + |
| 38 | +## Environment |
| 39 | + |
| 40 | +- MUST use `uv` for all Python tooling (running scripts, installing packages, building, etc.). Do NOT use `pip`, `poetry`, `pipx`, or bare `python`. |
| 41 | +- Tests hit the real Deno API (not mocked). Requires `DENO_DEPLOY_TOKEN` in `.env`. |
| 42 | +- Python 3.10+. |
| 43 | + |
| 44 | +## Running tests |
| 45 | + |
| 46 | +```bash |
| 47 | +uv run --env-file .env pytest |
| 48 | +``` |
| 49 | + |
| 50 | +Run a specific test: |
| 51 | + |
| 52 | +```bash |
| 53 | +uv run --env-file .env pytest tests/test_revisions.py::test_revisions_get_async -xvs |
| 54 | +``` |
| 55 | + |
| 56 | +## Test conventions |
| 57 | + |
| 58 | +- Async tests: `test_<name>_async`, decorated with `@pytest.mark.asyncio(loop_scope="session")` |
| 59 | +- Sync tests: `test_<name>_sync` |
| 60 | +- Shared fixtures in `conftest.py`: `async_shared_sandbox`, `shared_sandbox` |
| 61 | + |
| 62 | +## Code quality |
| 63 | + |
| 64 | +IMPORTANT: Before finishing any task, MUST run both of these: |
| 65 | + |
| 66 | +```bash |
| 67 | +uv run ruff format |
| 68 | +uv run ty check |
| 69 | +``` |
| 70 | + |
| 71 | +## Releasing |
| 72 | + |
| 73 | +Version is in `pyproject.toml`. Pushing a git tag `v<version>` triggers the publish workflow to PyPI. |
0 commit comments