pytest-nhsd-apim
A pytest extension for NHSDigital's API Mangement suite.
Installation
In your project's virtual environment
poetry add pytest-nhsd-apim
or if using pip directly
python -m pip install pytest-nhsd-apim
Usage
- create a python test file
- write a test using our custom authentication markers!
- enjoy!?
Testing
- run
make testto run test examples, located in this repo - after creating your file you can use the plugin as:
python -m pytest -p pytest_nhsd_apim test_nhsd_apim.py -s --apigee-proxy-name=<your-proxy-name>
Available tools
When installing this library in your project you can access some very handy tools, including our platform authenticators and our apigee api wrapper library.
Autheticators
We present a variety of authenticators including AuthorizationCodeAuthenticator, ClientCredentialsAuthenticator and TokenExchangeAuthenticator. The way of using them is simple. First you create the configuration object which will validate that your coniguration is correct on creation using pydantic, then pass the config to the authenticator and call get_token() on it.
from pytest_nhsd_apim.identity_service import ClientCredentialsConfig, ClientCredentialsAuthenticator
config = ClientCredentialsConfig(
environment={APIGEE_ENVIRONMENT},
identity_service_base_url={BASE_URL},
client_id={CLIENT_ID},
jwt_private_key={PRIVATE_KEY_PEM},
jwt_kid={KEY_ID},
)
authenticator=ClientCredentialsAuthenticator(config=config)
token=authenticator.get_token()
For a more detailed implementation on the rest of the authenticators please refer to the examples here.
Apigee APIs
We also present a variety off Apigee APIs with the benefit of a fully authenticated Apigee client ready to use. Just remember to export the following variables
# If you want the client to authenticate you...
export APIGEE_NHSD_NONPROD_USERNAME={my_username}
export APIGEE_NHSD_NONPROD_PASSWORD={my_password}
export APIGEE_NHSD_NONPROD_OTP_KEY={my_otp}
# Or alternatively, if you already have a token you can pass it and the client will use it.
export APIGEE_ACCESS_TOKEN={access_token}
#NOTE: in case both sets of credentials are defined, the username and password take presedence, this is so the Apigee client can keep itself authenticated all the time.
from pytest_nhsd_apim.apigee_apis import ApigeeNonProdCredentials, DeveloperAppsAPI
config = ApigeeNonProdCredentials()
client = ApigeeClient(config=config)
apps = DeveloperAppsAPI(client=client)
print(apps.list_aps('lucas.fantini@nhs.net'))
The APIs we offer at the moment are:
| API | Methods | Documentation |
|---|---|---|
| DeveloperAppsAPI | here | Overview |
| ApiProductsAPI | here | Overview |
| DebugSessionsAPI | here | Overview |
| AccessTokensAPI | here | Overview |
| AppKeysAPI | here | Overview |
For a more detailed implementation of the available APIs please refer to the tests here. We will keep adding APIs with time, if you are looking for a particular APIs not listed above please feel free to open a pull request and send it to us.
Metadata
Release files for pytest-nhsd-apim 6.0.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_nhsd_apim-6.0.14.tar.gz | 41.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_nhsd_apim-6.0.14-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 78.6 kB
Release files / pytest_nhsd_apim-6.0.14.tar.gz
| Download URL | pytest_nhsd_apim-6.0.14.tar.gz |
|---|---|
| Size | 41.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0de4010ad062d7a2791d3c09baab73f176fb8743b20a2c0ae026bdadf067819
|
|
BLAKE2b-256 checksum How to use checksums |
9870cfb5f831f43eb0b6966d2f5c2f8fd68ca1996289726b8456709c0999c58d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / pytest_nhsd_apim-6.0.14-py3-none-any.whl
| Download URL | pytest_nhsd_apim-6.0.14-py3-none-any.whl |
|---|---|
| Size | 37.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2d2649d05ba33dd51613d3d89d7a5524109097696518895f8c9425c4cfd8dbc
|
|
BLAKE2b-256 checksum How to use checksums |
d664e0829d8752f21b9d2d8976d413584d9cb5d39cfc924c34d52bccb4dcac43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency log