onboard.client


Nameonboard.client JSON
Version 1.9.4 PyPI version JSON
download
home_pagehttps://github.com/onboard-data/client-py
SummaryOnboard API SDK
upload_time2023-09-15 19:40:07
maintainer
docs_urlNone
authorNathan Merritt, John Vines
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Onboard Portal Python SDK

![PyPI](https://img.shields.io/pypi/v/onboard.client)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/onboard.client)
![PyPI - Status](https://img.shields.io/pypi/status/onboard.client)
![PyPI - License](https://img.shields.io/pypi/l/onboard.client)

This package provides Python bindings to Onboard Data's [building data API](https://portal.onboarddata.io).
For more details, you can navigate to the API & Docs Page to read the Getting Started Documentation section in the portal.
You'll have access to this page once you've signed up for our sandbox or you've been given access to your organization's account.

## API Access

You'll need an API key or existing account in order to use this client. If you don't have one and would like to start prototyping against an example building please [request a key here](https://onboarddata.io/sandbox).

Once you have a key, data access is explicitly granted by attaching one or more 'scopes' to the key. Our endpoints are grouped by scope on the [swagger documentation](https://api.onboarddata.io/swagger/) viewer.

You can also learn more about this client [on our docs!](https://onboard-api-wrappers-documentation.readthedocs.io/en/latest/index.html)

## Client usage example

First, you'll need to install the client (requires Python >= `3.7`)

```bash
$ pip install onboard.client
```

Now you can use the client to fetch timeseries data for sensors by building or based on type. This example requires an API key with the scopes `general` and `buildings:read`.

```python
from onboard.client import OnboardClient
client = OnboardClient(api_key='ob-p-your-key-here')

client.whoami()  # verify access & connectivity

client.get_all_point_types()  # retrieve available types of sensors

# retrieve the past 6 hours of data for sensors measuring CO2 ppm
from datetime import datetime, timezone, timedelta
from onboard.client.models import PointSelector, TimeseriesQuery, PointData
from typing import List

query = PointSelector()
query.point_types = ['Zone Carbon Dioxide']
query.buildings = ['Office Building']  # one of the example buildings available in the sandbox
selection = client.select_points(query)
end = datetime.utcnow().replace(tzinfo=timezone.utc)
start = end - timedelta(hours=6)

timeseries_query = TimeseriesQuery(point_ids=selection['points'], start=start, end=end)  # Or `TimeseriesQuery(selector=query, ...)`

sensor_metadata = client.get_points_by_ids(selection['points'])
sensor_data: List[PointData] = list(client.stream_point_timeseries(timeseries_query))
```

### Retries
The OnboardClient also exposes urllib3.util.retry.Retry to allow configuring retries in the event of a network issue. An example for use would be

```python
from onboard.client import OnboardClient
from urlilib3.util.retry import Retry

retry = Retry(total=3, backoff_factor=0.3, status_forcelist=(500, 502, 504))
client = OnboardClient(api_key='ob-p-your-key-here', retry=retry)

```

## Staging client usage

We provide an additional client object for users who wish to modify their building equipment and points in the "staging area" before those metadata are promoted to the primary tables. API keys used with the staging client require the `staging` scope, and your account must be authorized to perform `READ` and `UPDATE` operations on the building itself.

The staging area provides a scratchpad interface, where arbitrary additional columns can be added to points or equipment by using the prefix `p.` or `e.`. Any un-prefixed, user-added columns will be attached to points. Each update dictionary can modify a point, equipment or both at the same time (which implicitly reparents the point to the equipment). Each update should `p.topic` and/or `e.equip_id` to identify to the system where to apply the write. If a `topic` and `equip_id` are provided together in the same object then the system will associate that point with that equipment.

Updates use `PATCH` semantics, so only provided fields will be written to. Check-and-set concurrency control is available. To use it, include a `.cas` field with a current value to verify before processing the update. Please see the `update` object in the example below for more details.

The staging client supports the same urllib3.util.retry.Retry support that the standard client has.

```python
from onboard.client.staging import OnboardStagingClient

staging = OnboardStagingClient(api_key='ob-p-your-key-here')

buildings = client.get_all_buildings()  # using OnboardClient from above example
all_building_details = staging.get_staging_building_details()  # a list of building-level staging information objects

building_id: int = 0  # yours here

equipment_and_points_csv = staging.get_staged_equipment_csv(building_id)  # easy to load straight into a pandas.DataFrame

# or as Python objects
equipment = staging.get_staged_equipment(building_id)
equipment_and_points = staging.get_equipment_points(building_id)

update = [
    # keys to identify the equipment and point we are modifying
    {'e.equip_id':'ahu-1', 'p.topic':'org/building/4242/my-sensor',
    # an update to a known field: point.name
    'p.name': 'I am renaming the name field on the point to this string'
    # an optional check-and-set guard for the name update
    'p.name.cas' 'this row update will fail unless the point name matches this CAS value',
    # arbitrary user-defined fields are supported, prefix them to indicate destination
    'p.your_custom_field': 'keep track of something on the point here',
    'p.custom_non-string_field': 107.5,
    'e.custom_equip_field': 'this field will get saved on the equipment, not the point'}
]
# concurrent write exceptions and other issues are reported here
# each update dictionary is processed separately so a given update may partially succeed
row_write_errors = staging.update_staged_equipment(building_id, update)
```

## License

 Copyright 2018-2021 Onboard Data Inc

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/onboard-data/client-py",
    "name": "onboard.client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Nathan Merritt, John Vines",
    "author_email": "support@onboarddata.io",
    "download_url": "https://files.pythonhosted.org/packages/48/e1/01a068e2a95444476580671ef185f37b66291441efa452805a0829daefa8/onboard.client-1.9.4.tar.gz",
    "platform": null,
    "description": "# Onboard Portal Python SDK\n\n![PyPI](https://img.shields.io/pypi/v/onboard.client)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/onboard.client)\n![PyPI - Status](https://img.shields.io/pypi/status/onboard.client)\n![PyPI - License](https://img.shields.io/pypi/l/onboard.client)\n\nThis package provides Python bindings to Onboard Data's [building data API](https://portal.onboarddata.io).\nFor more details, you can navigate to the API & Docs Page to read the Getting Started Documentation section in the portal.\nYou'll have access to this page once you've signed up for our sandbox or you've been given access to your organization's account.\n\n## API Access\n\nYou'll need an API key or existing account in order to use this client. If you don't have one and would like to start prototyping against an example building please [request a key here](https://onboarddata.io/sandbox).\n\nOnce you have a key, data access is explicitly granted by attaching one or more 'scopes' to the key. Our endpoints are grouped by scope on the [swagger documentation](https://api.onboarddata.io/swagger/) viewer.\n\nYou can also learn more about this client [on our docs!](https://onboard-api-wrappers-documentation.readthedocs.io/en/latest/index.html)\n\n## Client usage example\n\nFirst, you'll need to install the client (requires Python >= `3.7`)\n\n```bash\n$ pip install onboard.client\n```\n\nNow you can use the client to fetch timeseries data for sensors by building or based on type. This example requires an API key with the scopes `general` and `buildings:read`.\n\n```python\nfrom onboard.client import OnboardClient\nclient = OnboardClient(api_key='ob-p-your-key-here')\n\nclient.whoami()  # verify access & connectivity\n\nclient.get_all_point_types()  # retrieve available types of sensors\n\n# retrieve the past 6 hours of data for sensors measuring CO2 ppm\nfrom datetime import datetime, timezone, timedelta\nfrom onboard.client.models import PointSelector, TimeseriesQuery, PointData\nfrom typing import List\n\nquery = PointSelector()\nquery.point_types = ['Zone Carbon Dioxide']\nquery.buildings = ['Office Building']  # one of the example buildings available in the sandbox\nselection = client.select_points(query)\nend = datetime.utcnow().replace(tzinfo=timezone.utc)\nstart = end - timedelta(hours=6)\n\ntimeseries_query = TimeseriesQuery(point_ids=selection['points'], start=start, end=end)  # Or `TimeseriesQuery(selector=query, ...)`\n\nsensor_metadata = client.get_points_by_ids(selection['points'])\nsensor_data: List[PointData] = list(client.stream_point_timeseries(timeseries_query))\n```\n\n### Retries\nThe OnboardClient also exposes urllib3.util.retry.Retry to allow configuring retries in the event of a network issue. An example for use would be\n\n```python\nfrom onboard.client import OnboardClient\nfrom urlilib3.util.retry import Retry\n\nretry = Retry(total=3, backoff_factor=0.3, status_forcelist=(500, 502, 504))\nclient = OnboardClient(api_key='ob-p-your-key-here', retry=retry)\n\n```\n\n## Staging client usage\n\nWe provide an additional client object for users who wish to modify their building equipment and points in the \"staging area\" before those metadata are promoted to the primary tables. API keys used with the staging client require the `staging` scope, and your account must be authorized to perform `READ` and `UPDATE` operations on the building itself.\n\nThe staging area provides a scratchpad interface, where arbitrary additional columns can be added to points or equipment by using the prefix `p.` or `e.`. Any un-prefixed, user-added columns will be attached to points. Each update dictionary can modify a point, equipment or both at the same time (which implicitly reparents the point to the equipment). Each update should `p.topic` and/or `e.equip_id` to identify to the system where to apply the write. If a `topic` and `equip_id` are provided together in the same object then the system will associate that point with that equipment.\n\nUpdates use `PATCH` semantics, so only provided fields will be written to. Check-and-set concurrency control is available. To use it, include a `.cas` field with a current value to verify before processing the update. Please see the `update` object in the example below for more details.\n\nThe staging client supports the same urllib3.util.retry.Retry support that the standard client has.\n\n```python\nfrom onboard.client.staging import OnboardStagingClient\n\nstaging = OnboardStagingClient(api_key='ob-p-your-key-here')\n\nbuildings = client.get_all_buildings()  # using OnboardClient from above example\nall_building_details = staging.get_staging_building_details()  # a list of building-level staging information objects\n\nbuilding_id: int = 0  # yours here\n\nequipment_and_points_csv = staging.get_staged_equipment_csv(building_id)  # easy to load straight into a pandas.DataFrame\n\n# or as Python objects\nequipment = staging.get_staged_equipment(building_id)\nequipment_and_points = staging.get_equipment_points(building_id)\n\nupdate = [\n    # keys to identify the equipment and point we are modifying\n    {'e.equip_id':'ahu-1', 'p.topic':'org/building/4242/my-sensor',\n    # an update to a known field: point.name\n    'p.name': 'I am renaming the name field on the point to this string'\n    # an optional check-and-set guard for the name update\n    'p.name.cas' 'this row update will fail unless the point name matches this CAS value',\n    # arbitrary user-defined fields are supported, prefix them to indicate destination\n    'p.your_custom_field': 'keep track of something on the point here',\n    'p.custom_non-string_field': 107.5,\n    'e.custom_equip_field': 'this field will get saved on the equipment, not the point'}\n]\n# concurrent write exceptions and other issues are reported here\n# each update dictionary is processed separately so a given update may partially succeed\nrow_write_errors = staging.update_staged_equipment(building_id, update)\n```\n\n## License\n\n Copyright 2018-2021 Onboard Data Inc\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Onboard API SDK",
    "version": "1.9.4",
    "project_urls": {
        "Homepage": "https://github.com/onboard-data/client-py"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "68d62ee3273b7b641a2965a4efd4f79f445cb62af627662c141c059997a30c37",
                "md5": "99c0a194e3dac9e9f3bebad4bb3e348b",
                "sha256": "c1741bf5599528e3657424f0910c5e12e7e982ced76bdc74fc458a085344686c"
            },
            "downloads": -1,
            "filename": "onboard.client-1.9.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "99c0a194e3dac9e9f3bebad4bb3e348b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 18065,
            "upload_time": "2023-09-15T19:40:05",
            "upload_time_iso_8601": "2023-09-15T19:40:05.370655Z",
            "url": "https://files.pythonhosted.org/packages/68/d6/2ee3273b7b641a2965a4efd4f79f445cb62af627662c141c059997a30c37/onboard.client-1.9.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "48e101a068e2a95444476580671ef185f37b66291441efa452805a0829daefa8",
                "md5": "8e01b0c2464fa2464218ff75c673fd54",
                "sha256": "454878aac3187189d3ccc7e36bcb860c57c51461f79f7fafe29f641bbd3fe254"
            },
            "downloads": -1,
            "filename": "onboard.client-1.9.4.tar.gz",
            "has_sig": false,
            "md5_digest": "8e01b0c2464fa2464218ff75c673fd54",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 18271,
            "upload_time": "2023-09-15T19:40:07",
            "upload_time_iso_8601": "2023-09-15T19:40:07.051319Z",
            "url": "https://files.pythonhosted.org/packages/48/e1/01a068e2a95444476580671ef185f37b66291441efa452805a0829daefa8/onboard.client-1.9.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-15 19:40:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "onboard-data",
    "github_project": "client-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "onboard.client"
}
        
Elapsed time: 0.36211s