Skip to content

Commit 71f9031

Browse files
authored
agents: Add AGENTS.md file (#71)
* agents: Add AGENTS.md file * Apply suggestion from @echarrod * gitignore: Remove .DS_STORE
1 parent 1156d88 commit 71f9031

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

.DS_Store

-6 KB
Binary file not shown.

AGENTS.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to agents (e.g. Claude Code / GitHub CoPilot) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
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.
8+
9+
## Architecture Overview
10+
11+
### Core Structure
12+
13+
- **`luno_python/base_client.py`**: Base HTTP client class (`BaseClient`) that handles:
14+
- HTTP requests using the `requests` library
15+
- Basic auth with API key and secret
16+
- Error handling and JSON parsing
17+
- User-Agent generation
18+
- URL construction with parameter substitution
19+
20+
- **`luno_python/client.py`**: Main `Client` class extending `BaseClient`. Contains ~100+ API methods auto-generated from the Luno API specification. Each method:
21+
- Wraps a specific API endpoint
22+
- Constructs the request object with parameters
23+
- Calls `do()` to make the HTTP request
24+
- Returns the API response as a dictionary
25+
26+
- **`luno_python/error.py`**: Custom `APIError` exception class for handling API errors
27+
28+
- **`luno_python/__init__.py`**: Exports package version
29+
30+
### Request/Response Flow
31+
32+
1. User calls a method on `Client` (e.g., `get_ticker(pair='XBTZAR')`)
33+
2. Method builds a request dict with parameters
34+
3. Method calls `self.do(method, path, req, auth)` from `BaseClient`
35+
4. `do()` makes HTTP request via `requests.Session`
36+
5. `do()` parses JSON response and checks for API error codes
37+
6. If error found, raises `APIError`; otherwise returns response dict
38+
39+
### API Design Patterns
40+
41+
- **Authentication**: HTTP Basic Auth with `api_key_id` and `api_key_secret`
42+
- **Path parameters**: Substituted using `{param_name}` syntax in paths
43+
- **Query parameters**: Passed via `params` in GET requests
44+
- **Error handling**: API returns `{"error_code": "...", "error": "..."}` on errors
45+
46+
## Development Commands
47+
48+
### Setup
49+
50+
```bash
51+
# Create and activate virtual environment
52+
python -m venv env
53+
source env/bin/activate # On Windows: env\Scripts\activate
54+
55+
# Install package in development mode with test dependencies
56+
pip install -e '.[test]'
57+
```
58+
59+
### Testing
60+
61+
```bash
62+
# Run all tests
63+
pytest
64+
65+
# Run specific test file
66+
pytest tests/test_client.py
67+
68+
# Run specific test
69+
pytest tests/test_client.py::test_client_do_basic
70+
71+
# Run with verbose output
72+
pytest -v
73+
74+
# Run with coverage
75+
pytest --cov=luno_python
76+
```
77+
78+
### Dependencies
79+
80+
- **Runtime**: `requests>=2.18.4`, `six>=1.11.0`
81+
- **Test**: `pytest`, `pytest-cov`, `requests_mock`
82+
83+
## Testing Approach
84+
85+
Tests use `requests_mock` to mock HTTP responses. The pattern:
86+
87+
1. Create a `Client` instance
88+
2. Mount mock adapter to session: `adapter.register_uri(method, url, ...)`
89+
3. Call client method and assert response
90+
91+
Recent additions test the `get_balances()` method with `account_id` parameter for filtering results by account.
92+
93+
## Git Workflow
94+
95+
When making changes:
96+
97+
1. Run `git pull` before creating a new branch
98+
2. Branch naming: `{username}-{issue-number}-{description}`
99+
3. Commit messages: Present tense, describe *why* not *what*
100+
4. Example: `"client: Add account_id parameter to get_balances method"`
101+
5. Push and create PR when ready
102+
103+
## Notes on Code Generation
104+
105+
The `client.py` file contains ~100+ methods that are auto-generated from Luno's API specification. When modifying or adding methods:
106+
107+
- Follow existing docstring format (includes HTTP method, path, permissions, parameter descriptions)
108+
- Each method constructs a `req` dict with parameters and calls `self.do()`
109+
- Type hints in docstrings use `:type param: type_name` format for Python 2 compatibility
110+
111+
## File Editing Requirements
112+
113+
Always ensure files end with a newline character. This maintains consistency with Git diffs and repository standards.

CLAUDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
For compatibility with multiple agents, the instructions are located at @AGENTS.md (see [AGENTS.md](./AGENTS.md).

0 commit comments

Comments
 (0)