fhir‑client
A lightweight, opinionated Python client for working with FHIR servers via the REST API.
📚 Table of Contents
- What is fhir‑client?
- Key Features
- Installation
- Getting Started
- Examples
- Contributing
- License
- Acknowledgements
🔍 What is fhir‑client?
fhir-client is a minimal wrapper around the FHIR REST API.
It handles:
- Standard CRUD operations (
GET,POST,PUT,DELETE) - Automatic JSON serialization/deserialization
- Optional authentication (Basic Auth, OAuth2)
Designed for developers who want to get started quickly without the overhead of a full‑blown SDK.
✨ Key Features
| Feature | Description |
|---|---|
| Simple API | FHIRClient exposes high‑level methods that map directly to FHIR operations. |
| Configurable | Base URL and authentication can be set globally or per request. |
📦 Installation
# From PyPI
pip install fhir-server-client
Developed and tested on Python 3.12
🚀 Getting Started
from fhir_client.client import FhirClient
# Create a client pointing at the HAPI FHIR demo server
client = FhirClient(base_url="https://hapi.fhir.org/baseR4")
# Perform a GET request for a Patient
patient = client.get("Patient", _id=123)
print(patient)
# Or use the generic GET method
patients = client.get("/Patient")
print(patients)
📚 Examples
Below are a few common use cases. Feel free to copy‑paste and adapt.
📦 Basic CRUD
# CREATE a new Patient
new_patient = {
"resourceType": "Patient",
"name": [{"family": "Doe", "given": ["John"]}],
"gender": "male",
"birthDate": "1974-12-25"
}
created = client.post("Patient", data=new_patient)
print("Created patient ID:", created["id"])
# READ the newly created Patient
patient = client.get("Patient", _id=created["id"])
print(patient)
# UPDATE the Patient
patient["name"][0]["given"] = ["Jonathan"]
updated = client.put("Patient", id=created["id"], data=patient)
print("Updated patient:", updated)
# DELETE the Patient
client.delete(resource_type="Patient", _id=patient["id"])
print("Patient deleted.")
🔍 Search & Filtering
# Search for patients named "John" with a minimum age of 18
results = client.get("Patient", name="John", birthdate="ge1975-01-01")
for patient in results["entry"]:
print(patient["resource"]["id"], patient["resource"]["name"][0]["given"])
# Checking for and getting self, next and previous links
if client.has_self():
self_link = client.self
if client.has_next():
next_link = client.next
if client.has_previous():
previous_link = client.previous
The
getmethod accepts search parameters as python keyword arguments. Those are appended in the FHIR Search Query
🔐 Authentication
# Using Basic Auth
from fhir_client.auth import FhirAuth
auth = FhirAuth().set_basic_auth("username", "password")
client = FHIRClient("https://fhir.example.com", auth=auth)
# Using OAuth2 (client credentials flow)
from fhir_client.auth import FhirAuth
auth = FhirAuth().set_o_auth(
auth_url="https://auth.example.com/token",
client_id="client-id",
client_secret="client-secret"
)
client = FHIRClient(base_url="https://fhir.example.com", auth=auth)
🤝 Contributing (WORK IN PROGRESS)
We love contributions! Please read our CONTRIBUTING.md for guidelines on coding style, testing, and pull requests.
Steps to get started
- Fork the repo and clone it locally.
- Create a new branch (
git checkout -b feature/foo). - Write tests for your change.
- Run the test suite (
pytest). - Submit a pull request.
📄 License
MIT © 2026
See the LICENSE file for details.
🙏 Acknowledgements
Happy coding! 🎉
Metadata
Release files for fhir-server-client 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fhir_server_client-0.0.4.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fhir_server_client-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / fhir_server_client-0.0.4.tar.gz
| Download URL | fhir_server_client-0.0.4.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26f475a4feb2abbf278f904d932d68c16d95d0901d6c52be60bfd61250ccca33
|
|
BLAKE2b-256 checksum How to use checksums |
8205d34943fe89f0556e497f0eed3f6801b005638fba50aa27d1e99f488e4a11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / fhir_server_client-0.0.4-py3-none-any.whl
| Download URL | fhir_server_client-0.0.4-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c75a75233e804615c2186c598bb701e6c33799cc77deebff65e58d5a7b717dfd
|
|
BLAKE2b-256 checksum How to use checksums |
acb5087eb5bf0aa56b5b4228f40dfdf8bea8903179b6e596c348a0b152219ce0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|