Metadata-Version: 2.4
Name: hmrclib
Version: 0.1.2
Summary: Comprehensive typed Python client for the HMRC Developer Hub APIs (REST + OAuth2), with generated pydantic models for every published API.
Project-URL: Homepage, https://github.com/rodmena-limited/hmrclib
Project-URL: Repository, https://github.com/rodmena-limited/hmrclib
Project-URL: Documentation, https://github.com/rodmena-limited/hmrclib
Author-email: Rodmena Limited <farshid@rodmena.co.uk>
License: MIT License
        
        Copyright (c) 2026 Rodmena Limited
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: api-client,hmrc,making-tax-digital,mtd,oauth2,self-assessment,vat
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Requires-Dist: httpx<1,>=0.27
Requires-Dist: pydantic-settings<3,>=2.3
Requires-Dist: pydantic<3,>=2.7
Requires-Dist: pyyaml<7,>=6.0
Provides-Extra: dev
Requires-Dist: fastapi<1,>=0.111; extra == 'dev'
Requires-Dist: httpx<1,>=0.27; extra == 'dev'
Requires-Dist: mypy<2,>=1.10; extra == 'dev'
Requires-Dist: pytest-asyncio<1,>=0.23; extra == 'dev'
Requires-Dist: pytest-cov<6,>=5.0; extra == 'dev'
Requires-Dist: pytest<9,>=8.2; extra == 'dev'
Requires-Dist: ruff<1,>=0.5; extra == 'dev'
Requires-Dist: types-pyyaml<7,>=6.0; extra == 'dev'
Requires-Dist: uvicorn<1,>=0.30; extra == 'dev'
Provides-Extra: server
Requires-Dist: fastapi<1,>=0.111; extra == 'server'
Requires-Dist: uvicorn<1,>=0.30; extra == 'server'
Description-Content-Type: text/markdown

# hmrclib

Comprehensive, typed Python client for the **HMRC Developer Hub APIs** (Making Tax Digital).

`hmrclib` is a PyPI package that wraps every REST API published on the
[HMRC Developer Hub](https://developer.service.hmrc.gov.uk/api-documentation/docs/api/)
with:

- **Generated pydantic v2 models** for every OpenAPI schema in every API
- **Typed client classes** — one per API, one method per endpoint
- **Full OAuth2 support**: `client_credentials` (application-restricted),
  `authorization_code` + `refresh_token` (user-restricted), with an optional
  **FastAPI callback server** for the browser redirect journey
- **Strict typing** — the package itself is `mypy --strict` clean and
  `ruff` clean

## Installation

```bash
pip install hmrclib
# or, with the OAuth callback server extra:
pip install "hmrclib[server]"
```

## Quick start

```python
import os
from hmrclib import OAuth2Client, HMRCClient
from hmrclib.generated.clients import VatApiClient, VatRegisteredCompaniesApiClient

os.environ["HMRC_ENV"] = "sandbox"
os.environ["HMRC_CLIENT_ID"] = "..."
os.environ["HMRC_CLIENT_SECRET"] = "..."

oauth = OAuth2Client()
oauth.client_credentials("read:vat")

client = HMRCClient(oauth=oauth, scope="read:vat")
vat = VatApiClient(client)

# GET /organisations/vat/{vrn}/obligations
result = vat.get_organisations_vat_vrn_obligations(vrn="123456789")
print(result)
```

## Supported APIs

All **73 REST APIs** published on the HMRC Developer Hub are generated from
their official OpenAPI specifications (vendored under [`specs/`](specs/)),
including Making Tax Digital (Self Assessment, VAT, Property, CIS), Customs,
Lifetime ISA, Agent Authorisation, and the test-support APIs.

## OAuth2

```python
from hmrclib import OAuth2Client

oauth = OAuth2Client()
oauth.client_credentials("read:vat")  # application-restricted

# user-restricted: build the authorize URL, then exchange the code
url = oauth.authorization_url("hello", state="abc123")
# ... user completes the browser journey ...
token = oauth.authorization_code("CODE_FROM_REDIRECT")
token = oauth.refresh(token.refresh_token)  # keep it alive
```

### OAuth callback server (FastAPI)

```bash
uvicorn hmrclib.server:app --port 8300
```

Serve the registered redirect URI (e.g. `https://baseframe.rodmena.co.uk/oauth/hmrc/callback`),
capture the code and exchange it for tokens:

```bash
curl https://baseframe.rodmena.co.uk/oauth/hmrc/result
```

## Development

```bash
uv pip install -e ".[dev]"
ruff check .
mypy .
pytest
```

The generated code can be regenerated from the vendored specs:

```bash
python -m hmrclib.codegen --specs specs --out src/hmrclib/generated
```

## License

MIT. `hmrclib` is not affiliated with HMRC; the API specifications it
implements are © Crown copyright, available under the
[Open Government Licence v3.0](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/).
