Skip to main content

Aidbox client for python

Project description

Build Status codecov pypi


Aidbox client for python. This package provides an API for CRUD operations over Aidbox resources.

The library is based on fhir-py and the main difference between libraries in our case is the way they represent resource references (read more about differences).

Aidbox-py also going to support some Aidbox features like _assoc operation, AidboxQuery and so on.

Most examples from fhir-py readme also work for aidbox-py (but you need to replace FHIR client with AsyncAidboxClient/SyncAidboxClient). See base aidbox-py example below.

Getting started


Most recent version: pip install git+ PyPi: pip install aidboxpy

Async example

import asyncio
from aidboxpy import AsyncAidboxClient
from fhirpy.base.exceptions import (
    OperationOutcome, ResourceNotFound, MultipleResourcesFound

async def main():
    # Create an instance
    client = AsyncAidboxClient(
        authorization='Bearer TOKEN'

    # Search for patients
    resources = client.resources('Patient')  # Return lazy search set
    resources ='John').limit(10).page(2).sort('name')
    patients = await resources.fetch()  # Returns a list of AsyncAidboxResource

    # Get exactly one resource
        patient = await client.resources('Practitioner') \
    except ResourceNotFound:
    except MultipleResourcesFound:

    # Validate resource
        await client.resource(
    except OperationOutcome as e:
        print('Error: {}'.format(e))

    # Create Organization resource
    organization = client.resource(

    # Get patient resource by reference and delete
    patient_ref = client.reference('Patient', 'new_patient')
    patient_res = await patient_ref.to_resource()
    await patient_res.delete()

    # Iterate over search set and change organization
    org_resources = client.resources('Organization').search(active=False)
    async for org_resource in org_resources:
        org_resource['active'] = True

if __name__ == '__main__':
    loop = asyncio.get_event_loop()


Import library:

from aidboxpy import SyncAidboxClient


from aidboxpy import AsyncAidboxClient

To create AidboxClient instance use:

SyncAidboxClient(url, authorization='', extra_headers={})


AsyncAidboxClient(url, authorization='', extra_headers={})

Returns an instance of the connection to the server which provides:

  • .reference(resource_type, id, reference, **kwargs) - returns SyncAidboxReference/AsyncAidboxReference to the resource
  • .resource(resource_type, **kwargs) - returns SyncAidboxResource/AsyncAidboxResource which described below
  • .resources(resource_type) - returns SyncAidboxSearchSet/AsyncAidboxSearchSet



  • .serialize() - serializes resource
  • .get_by_path(path, default=None) – gets the value at path of resource
  • .save() - creates or updates resource instance
  • .delete() - deletes resource instance
  • .to_reference(**kwargs) - returns SyncAidboxReference/AsyncAidboxReference for this resource



  • .to_resource() - returns SyncAidboxResource/AsyncAidboxResource for this reference



  • .search(param=value)
  • .limit(count)
  • .page(page)
  • .sort(*args)
  • .elements(*args, exclude=False)
  • .include(resource_type, attr=None, recursive=False, iterate=False)
  • .revinclude(resource_type, attr=None, recursive=False, iterate=False)
  • .has(*args, **kwargs)
  • .assoc(elements)
  • async .fetch() - makes query to the server and returns a list of Resource filtered by resource type
  • async .fetch_all() - makes query to the server and returns a full list of Resource filtered by resource type
  • async .fetch_raw() - makes query to the server and returns a raw Bundle Resource
  • async .first() - returns Resource or None
  • async .get(id=None) - returns Resource or raises ResourceNotFound when no resource found or MultipleResourcesFound when more than one resource found (parameter 'id' is deprecated)
  • async .count() - makes query to the server and returns the total number of resources that match the SearchSet

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

aidboxpy-1.3.0.tar.gz (5.3 kB view hashes)

Uploaded source

Built Distribution

aidboxpy-1.3.0-py3-none-any.whl (5.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page