A Python client to interact with FHIR servers
Project description
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! 🎉
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fhir_server_client-0.0.4.tar.gz.
File metadata
- Download URL: fhir_server_client-0.0.4.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26f475a4feb2abbf278f904d932d68c16d95d0901d6c52be60bfd61250ccca33
|
|
| MD5 |
ef1467fff8eb2515e9494832fb2d453a
|
|
| BLAKE2b-256 |
8205d34943fe89f0556e497f0eed3f6801b005638fba50aa27d1e99f488e4a11
|
File details
Details for the file fhir_server_client-0.0.4-py3-none-any.whl.
File metadata
- Download URL: fhir_server_client-0.0.4-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c75a75233e804615c2186c598bb701e6c33799cc77deebff65e58d5a7b717dfd
|
|
| MD5 |
b952d70f43d594497270a9f3571530bb
|
|
| BLAKE2b-256 |
acb5087eb5bf0aa56b5b4228f40dfdf8bea8903179b6e596c348a0b152219ce0
|