Leyr publishes a full OpenAPI 3.x specification for its API. You can feed this spec into any OpenAPI-compatible code generator to produce a fully typed client library in your language of choice - Python, TypeScript, Java, C#, Go, Kotlin, Ruby, Swift, and many more.
The Leyr OpenAPI specification is available at:
https://api.leyr.io/openapi.json
You can also browse it interactively:
You need the OpenAPI Generator CLI. Pick whichever installation method suits your environment:
docker pull openapitools/openapi-generator-cli:v7.10.0
npm install -g @openapitools/openapi-generator-cli
brew install openapi-generator
For other options, see the official installation guide.
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v7.10.0 generate \
-i https://api.leyr.io/openapi.json \
-g python \
-o /local/leyr-client \
--skip-validate-spec \
-p packageName=leyr_client
This produces a leyr-client/ directory containing a fully typed Python package.
The generated client will include a requirements.txt with the necessary dependencies. Install them with:
pip install -r leyr-client/requirements.txt
import os
import leyr_client
from leyr_client.rest import ApiException
configuration = leyr_client.Configuration(
host="https://api.leyr.io"
)
configuration.api_key["leyr-client-id"] = os.environ["LEYR_CLIENT_ID"]
configuration.api_key["leyr-client-secret"] = os.environ["LEYR_CLIENT_SECRET"]
with leyr_client.ApiClient(configuration) as api_client:
care_units_api = leyr_client.CareUnitsApi(api_client)
try:
response = care_units_api.care_units_get_care_units(
emr="webdoc",
)
print(response)
except ApiException as e:
print(f"API error: {e}")
All request/response models are fully typed, giving you autocompletion and validation out of the box.
Replace -g python with any supported generator. Popular choices:
| Language / Framework | Generator flag |
|---|---|
| TypeScript (Axios) | typescript-axios |
| TypeScript (Fetch) | typescript-fetch |
| Java | java |
| C# | csharp |
| Kotlin | kotlin |
| Go | go |
| Ruby | ruby |
| Swift | swift5 |
| Dart | dart |
| Rust | rust |
For the full list of 40+ supported languages, see the OpenAPI Generator documentation.
--skip-validate-spec - the Leyr spec uses some advanced OpenAPI features that may trigger warnings in the validator but generate correctly.v7.10.0) rather than latest helps ensure reproducible builds across your team.--global-property apiTests=false,modelTests=false to avoid generating placeholder test files.ruff for Python, prettier for TypeScript) on the generated code helps keep a consistent style.--config to keep your generate command clean and version-controllable.The generated client will include support for the x-leyr-client-id and x-leyr-client-secret headers used by Leyr API. You need to configure these with your application credentials.
If you haven't set up your developer application yet, follow the Getting Started guide:
Getting StartedResource IDs
It is possible to use different types of resource IDs in requests to Leyr API. Get resource details, book appointments, create medical notes and documents using EHR IDs, HSA IDs and more.
Test Data for our EHRs
Here we have prepared some test data for you to try out integration with our EHRs in Leyr Sandbox. It is first and foremost applicable when using Leyr credentials, as described in the EHR configuration guide.