|
| 1 | +# Agent Guide: IMPC API |
| 2 | + |
| 3 | +This document provides context, rules, and guidelines for AI agents (like GitHub Copilot, Cursor, or Gemini) working on the `impc-api` codebase. |
| 4 | + |
| 5 | +## 🛠 Tech Stack |
| 6 | +- **Language**: Python 3.10+ |
| 7 | +- **Data Handling**: `pandas` (primary output format for dataframes) |
| 8 | +- **Networking**: `requests` (for API calls) |
| 9 | +- **Validation**: `pydantic` (for input/parameter validation) |
| 10 | +- **Testing**: `pytest` |
| 11 | +- **Progress Tracking**: `tqdm` |
| 12 | +- **Environment**: Optimized for Jupyter Notebooks/Lab |
| 13 | + |
| 14 | +## 📂 Project Structure |
| 15 | +- `impc_api/`: Core package directory. |
| 16 | + - `solr_request.py`: Standard single-request logic. |
| 17 | + - `batch_solr_request.py`: Logic for large/chunked requests. |
| 18 | + - `utils/`: |
| 19 | + - `validators.py`: Pydantic models for core/field validation. |
| 20 | + - `core_fields.json`: Source of truth for valid Solr cores and their allowed fields. |
| 21 | + - `warnings.py`: Custom warning categories (e.g., `InvalidCoreWarning`). |
| 22 | +- `tests/`: Unit and integration tests. |
| 23 | + |
| 24 | +## 📏 Coding Conventions & Rules |
| 25 | + |
| 26 | +### 1. Validation First |
| 27 | +- Always validate `core` and `fl` (field list) parameters using `CoreParamsValidator` in `impc_api/utils/validators.py`. |
| 28 | +- Validation should generally issue **Warnings** rather than raising Errors to avoid breaking user workflows, unless the request is physically impossible (e.g., unsupported download format). |
| 29 | +- Refer to `impc_api/utils/core_fields.json` when suggesting new fields. |
| 30 | + |
| 31 | +### 2. Jupyter Compatibility |
| 32 | +- Maintain compatibility with `ipykernel` and `notebook`. |
| 33 | +- Ensure output is clean and informative for notebook users (e.g., using `tqdm` for progress bars in batch requests). |
| 34 | + |
| 35 | +### 3. Type Hinting |
| 36 | +- Use explicit type hints for all function signatures and complex variables. |
| 37 | +- Use `typing.Dict`, `typing.List`, and `typing.Optional` as needed. |
| 38 | + |
| 39 | +### 4. Testing |
| 40 | +- **Always** verify changes by running `pytest`. |
| 41 | +- New features should include corresponding tests in `tests/`. |
| 42 | +- Use `pytest.mark.parametrize` for testing multiple API scenarios. |
| 43 | + |
| 44 | +## ⌨️ Key Commands |
| 45 | +```bash |
| 46 | +# Install for development |
| 47 | +pip install -e .[dev] |
| 48 | + |
| 49 | +# Run all tests |
| 50 | +pytest |
| 51 | + |
| 52 | +# Run a specific test file |
| 53 | +pytest tests/test_solr_request.py |
| 54 | + |
| 55 | +# Check linting (if configured) |
| 56 | +# Currently, the project uses standard Python conventions. |
| 57 | +``` |
| 58 | + |
| 59 | +## 🚧 Boundaries & Constraints |
| 60 | +- **Secrets**: Never commit API keys or sensitive internal URLs. The IMPC API is public, but always double-check. |
| 61 | +- **Dependencies**: Do not add new heavy dependencies without consulting the `pyproject.toml`. |
| 62 | +- **API Strain**: When implementing new features, ensure they don't put unnecessary load on the IMPC Solr servers. Use `batch_size` defaults appropriately. |
| 63 | + |
| 64 | +## 💡 Common Tasks |
| 65 | +- **Updating Allowed Fields**: Add the field name to the corresponding core list in `impc_api/utils/core_fields.json`. |
| 66 | +- **Modifying Validation**: Edit `impc_api/utils/validators.py` and ensure `pydantic` models are updated. |
0 commit comments