These instructions apply to the whole repository.
- Python client for the Trakt.tv API
- Main package:
trakt/ - Tests:
tests/ - Packaging and tooling:
setup.py,requirements.txt,testing-requirements.txt,Makefile
- No additional repo-local instruction files are checked in here.
- If additional instruction files appear later, read them before editing code.
- API surface most agents touch first:
trakt/users.py - HTTP/client layer:
trakt/api.py,trakt/core.py,trakt/decorators.py - Shared data helpers:
trakt/mixins.py,trakt/utils.py - Errors and exception mapping:
trakt/errors.py
- Many public methods are generator-based wrappers: they yield a URI, optional payload, then receive processed JSON back from the decorator layer.
trakt.corekeeps global client and auth state; changes there affect the entire package.DataClassMixinandIdsMixinare the main composition helpers for model wrappers.ListEntry,PublicList, andUserListshow the preferred pattern for converting nested API payloads into typed objects.
- Install runtime dependencies:
python3 -m pip install -r requirements.txt - Install test and lint dependencies:
python3 -m pip install -r testing-requirements.txt - Combined setup:
make init - Run lint:
make style - Run tests:
make test - Run coverage:
make coverage - Run pytest directly:
python3 -m pytest tests - Run a single test:
python3 -m pytest tests/test_users.py::test_user_list -q - Run one file:
python3 -m pytest tests/test_users.py -q - Run by name:
python3 -m pytest tests/test_users.py -k test_user_list -q - Build release artifacts:
python3 -m pip install --upgrade build && python3 -m build - Legacy packaging still works:
python3 setup.py sdist bdist_wheel - Docs build:
make docs
- Keep edits narrow and local to the modules needed for the task.
- Prefer existing helpers and patterns over new abstractions.
- When touching
trakt/users.py, watch for nested model conversion and mixin-based attribute delegation. - When touching
trakt/api.py, keep request, decode, and error handling paths aligned with current behavior. - When touching tests, prefer updating mock payloads over mocking deeper internals.
- Keep tests deterministic and offline;
tests/conftest.pypatches the Trakt client with local mock responses. - Do not delete or rename public APIs without a strong reason.
- Do not reformat unrelated files.
- If a change affects packaging, authentication, or response decoding, update tests before considering the work done.
- Match the surrounding file. This codebase is not uniformly modernized, so local consistency matters more than broad cleanup.
- Import order should be stdlib, third-party, then local
trakt.*imports. Letisorthandle ordering. - Prefer absolute imports within the package, which is the dominant style here.
- Preserve existing module docstrings and UTF-8 source headers in legacy files.
- Avoid wholesale reflowing. Keep line wrapping close to the nearby code.
- Use single quotes where the file already does so.
- Use type hints sparingly and locally. New public APIs can be annotated, but do not force a repo-wide typing migration.
- Common typing patterns here are
dataclass,NamedTuple,Optional,Union, and small container annotations on public surfaces. - Naming is conventional Python:
snake_casefor functions and variables,PascalCasefor classes,UPPER_SNAKE_CASEfor constants, and leading underscores for private helpers. - Public exports are often tracked with
__all__; update it when the import surface changes on purpose. - Keep module and class docstrings short and factual.
- The request layer uses generator-based decorators in
trakt.decorators; preserve that pattern for new endpoints that fit the existing model. trakt.corestores global client and auth state; be careful when editing code that mutates module-level configuration.
- Use the repository’s custom exceptions in
trakt.errorsfor known Trakt failure modes. - Raise
ValueErrorfor invalid user input and parameter validation. - Reserve
RuntimeErrorfor internal impossible states, not ordinary bad input. - Do not swallow exceptions unless the surrounding code already does that for compatibility.
- Preserve the current
BadResponseExceptionbehavior when JSON decoding fails. - Follow the existing
HttpClientandTokenAuthpatterns instead of adding a new request stack.
- Many response objects are thin wrappers over API payloads; preserve fields that are already exposed.
- Prefer explicit copying or filtering when normalizing JSON unless the current module intentionally mutates the input.
- Keep list and collection classes iterable when the public API exposes them that way.
- If you add new model properties, make sure they do not break existing
__getattr__delegation in mixins and dataclasses. - Keep public return types stable. The tests generally assert classes, counts, and a few important field values.
setup.pyreadsREADME.rstandrequirements.txt; keep those files in sync with packaging changes.requirements.txtis runtime-only;testing-requirements.txtadds pytest, pytest-cov, and flake8.- The docs workflow depends on
make docsand may rewritetrakt/__version__.pyfrom git tags. - If you touch packaging metadata, check the release workflow as well as the local build command.
- Avoid adding a second packaging path unless the repo already needs it.
- Run
pytestfor behavior changes. - For CLI or packaging changes, run the relevant Makefile target too.
- For a single test, use
python3 -m pytest tests/test_users.py::test_user_list -q. - For import-only changes, run
pre-commit run isort --files <touched files>or the equivalent touched-files-onlyisortinvocation. - When a test fails because of data-shape drift, update the mock payloads and the assertions together.
- Before finishing, sanity-check the exact command an agent would run for the change.
- Prefer atomic commits: one intent, one self-contained change.
- Keep commits small enough to review and revert independently.
- Separate refactors, behavior changes, tests, and docs when practical.
- Follow the principles from https://cbea.ms/git-commit/.
- Use a short imperative subject line.
- Include a blank line after the subject.
- Add a
Co-authored-bytrailer for LLM-assisted commits.