Skip to main content

Build Status codecov pypi

aidbox-py

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

Install

Most recent version: pip install git+https://github.com/beda-software/aidbox-py.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(
        'http://localhost:8080',
        authorization='Bearer TOKEN'
    )

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

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

    # Validate resource
    try:
        await client.resource(
            'Person',
            custom_prop='123',
            telecom=True
        ).is_valid()
    except OperationOutcome as e:
        print('Error: {}'.format(e))

    # Create Organization resource
    organization = client.resource(
        'Organization',
        name='beda.software',
        active=False
    )
    await organization.save()

    # 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
        await org_resource.save()


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

API

Import library:

from aidboxpy import SyncAidboxClient

or

from aidboxpy import AsyncAidboxClient

To create AidboxClient instance use:

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

or

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

SyncAidboxResource/AsyncAidboxResource

provides:

  • .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

SyncAidboxReference/AsyncAidboxReference

provides:

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

SyncAidboxSearchSet/AsyncAidboxSearchSet

provides:

  • .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

Metadata

Release files for aidboxpy 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aidboxpy 1.3.0
File Size Uploaded Provenance
aidboxpy-1.3.0.tar.gz 5.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aidboxpy 1.3.0
File Interpreter ABI Platform
aidboxpy-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / aidboxpy-1.3.0.tar.gz

Download URL aidboxpy-1.3.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
225f72ef59e99d05abf5ea26fdeec3f666ca92b2d3219fb064b76b5a56d3a28a
BLAKE2b-256 checksum
How to use checksums
772be9f29ad0bf48afa9d95e2db00acde7040ab8dd35ba598679b98675210aa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / aidboxpy-1.3.0-py3-none-any.whl

Download URL aidboxpy-1.3.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a5b3e031272d1be06b2bbec5771fdae90f40b331822e191743e8b449389f674
BLAKE2b-256 checksum
How to use checksums
f953e08364534813de33a0023f6be25c233fc5f4b3f08f48d40ed26872df85ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for aidboxpy 1.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page