This file provides guidance to agents (e.g. Claude Code / GitHub CoPilot) when working with code in this repository.
This is the Luno Python SDK, a wrapper for the Luno API (cryptocurrency exchange platform). The package provides a Python client for interacting with Luno's REST API, supporting operations like account management, trading, fund transfers, and market data queries.
-
luno_python/base_client.py: Base HTTP client class (BaseClient) that handles:- HTTP requests using the
requestslibrary - Basic auth with API key and secret
- Error handling and JSON parsing
- User-Agent generation
- URL construction with parameter substitution
- HTTP requests using the
-
luno_python/client.py: MainClientclass extendingBaseClient. Contains ~100+ API methods auto-generated from the Luno API specification. Each method:- Wraps a specific API endpoint
- Constructs the request object with parameters
- Calls
do()to make the HTTP request - Returns the API response as a dictionary
-
luno_python/error.py: CustomAPIErrorexception class for handling API errors -
luno_python/__init__.py: Exports package version
- User calls a method on
Client(e.g.,get_ticker(pair='XBTZAR')) - Method builds a request dict with parameters
- Method calls
self.do(method, path, req, auth)fromBaseClient do()makes HTTP request viarequests.Sessiondo()parses JSON response and checks for API error codes- If error found, raises
APIError; otherwise returns response dict
- Authentication: HTTP Basic Auth with
api_key_idandapi_key_secret - Path parameters: Substituted using
{param_name}syntax in paths - Query parameters: Passed via
paramsin GET requests - Error handling: API returns
{"error_code": "...", "error": "..."}on errors
# Create and activate virtual environment
python -m venv env
source env/bin/activate # On Windows: env\Scripts\activate
# Install package in development mode with test dependencies
pip install -e '.[test]'# Run all tests
pytest
# Run specific test file
pytest tests/test_client.py
# Run specific test
pytest tests/test_client.py::test_client_do_basic
# Run with verbose output
pytest -v
# Run with coverage
pytest --cov=luno_python- Runtime:
requests>=2.18.4,six>=1.11.0 - Test:
pytest,pytest-cov,requests_mock
Tests use requests_mock to mock HTTP responses. The pattern:
- Create a
Clientinstance - Mount mock adapter to session:
adapter.register_uri(method, url, ...) - Call client method and assert response
Recent additions test the get_balances() method with account_id parameter for filtering results by account.
When making changes:
- Run
git pullbefore creating a new branch - Branch naming:
{username}-{issue-number}-{description} - Commit messages: Present tense, describe why not what
- Example:
"client: Add account_id parameter to get_balances method" - Push and create PR when ready
The client.py file contains ~100+ methods that are auto-generated from Luno's API specification. When modifying or adding methods:
- Follow existing docstring format (includes HTTP method, path, permissions, parameter descriptions)
- Each method constructs a
reqdict with parameters and callsself.do() - Type hints in docstrings use
:type param: type_nameformat for Python 2 compatibility
Always ensure files end with a newline character. This maintains consistency with Git diffs and repository standards.