Guidance for AI assistants working in this repository.
pip install -e ".[dev]"
pytest tests/ -vNo network access is needed for tests; every HTTP call is mocked with unittest.mock.patch on requests.Session.get / requests.Session.post.
datalastic/
__init__.py public exports (Client, models, exceptions)
client.py Client + _get/_post/_handle + base URLs + stat()
vessels.py VesselsResource (8 methods)
ports.py PortsResource (find, get)
routes.py RoutesResource (calculate)
intel.py IntelResource (8 maritime_reports endpoints)
reports.py ReportsResource (submit, get, list_all)
models.py dict-backed data classes, each with .raw and __repr__
exceptions.py exception hierarchy
tests/test_client.py
- Auth is a query parameter.
api-keyis appended to params in_get()and injected into the JSON body in_post(). Never a header. - Three base URLs.
BASE_V0(default),BASE_EXT(sea routes, SAT-E),BASE_MR(allintelendpoints). Passbase=to_get(). - Date params are renamed. Python
from_date/to_dateare sent as thefrom/toquery keys.vessel_typeinvessels.find()is sent astypeto avoid shadowing the builtin. - None filtering. Always strip
Nonevalues before building the request ({k: v for k, v in params.items() if v is not None}). - Validate before HTTP. Required-parameter checks raise
ValueErrorbefore any request is made. - Bulk uses repeated params.
vessels.bulk()builds a list of(key, value)tuples so identifiers are sent asmmsi=x&mmsi=y. - Response unwrapping.
_get()/_post()unwrap the envelope and returnbody["data"]directly; callers use the returned value as the model data. List endpoints map each element into a model. - Models never raise on missing fields. They use
.get()and keep the raw payload in.raw.
DatalasticError
├── AuthenticationError 401
├── InsufficientCreditsError 402
├── NotFoundError 404
├── RateLimitError 429
└── APIError everything else; has .status_code
Timeouts, connection errors, non-JSON bodies, and missing data keys all map
to APIError.
- Build fake responses with the
make_response()/ok()helpers intests/test_client.py. - Every resource method has a happy-path test plus validation-error tests.
- Assert the called URL prefix to confirm the correct base URL is used.
- Assert query params / JSON body to confirm renaming and auth injection.
- Keep tests offline — never hit the live API.