Skip to main content


onc: client library for accessing Oceans 3.0 API

PyPI Latest Release PyPI Supported Versions License - Apache 2.0 Frontiers in Marine Science Paper

onc is a Python client library that facilitates access to scientific data hosted by Ocean Networks Canada through the Oceans 3.0 API public web services. It can help you explore and download our data, by consuming our discovery, data product download, archive file download, and near real-time data access services.

Getting Started

Installation

onc can be installed from PyPI:

pip install onc

Obtaining a token

A unique Oceans 3.0 API token is required to access our data. To obtain a token, follow the steps below:

  1. Register for an Oceans 3.0 account at https://data.oceannetworks.ca/Registration.

  2. Log into your account at https://data.oceannetworks.ca by clicking the Log In link.

  3. Click the Profile link (top right corner) to access your account profile.

  4. Access the Web Services API tab and click Copy Token.

  5. If you forget your token, you can always find it again in your Oceans 3.0 account profile.

Searching with discovery methods

To download ONC data, you need to specify the type of data you require and where in particular (i.e. location, device) it originates from.

In the Oceans 3.0 API, there's a unique code that identifies every location, device, property, data product type, etc. Include these codes in a group of filters (these will be used as URL parameters when making HTTP requests) that determine the data you're interested in.

Discovery methods allow you to explore the hierarchy of the ONC database to obtain the codes for your filters (they work like a "search" function).

The example below uses the getLocations method to search for locations that include "Burrard" in their name (i.e. "Burrard Inlet"):

from onc import ONC

onc = ONC("YOUR_TOKEN")
onc = ONC() # This works if the env variable "ONC_TOKEN" is set

onc.getLocations({"locationName": "Burrard"})

The previous code prints a list with locations that match the search filters provided. Each location in the list includes a dataSearchURL that points to the Data Search Tool, and a locationCode ("BIPP" and "BISS" in this example) that can be used to continue searching "inside" it, as in the following example:

onc.getDeviceCategories({"locationCode": "BIIP"})
onc.getDataProducts({"locationCode": "BIIP", "deviceCategoryCode": "CTD"})

Check more on the discovery methods guide and code examples.

Downloading data products

Once you determine the exact dictionary of filters that identifies the data you are interested in, there are multiple methods to download it.

One method is to request the ONC servers to generate a custom data product with the data. This is done through the data product download methods.

The following example downloads two PNG files with plots for 30 seconds of data from a CTD in Campbell River:

params = {
    "locationCode": "BIIP",
    "deviceCategoryCode": "CTD",
    "dataProductCode": "TSSP",
    "extension": "png",
    "dateFrom": "2019-06-20T00:00:00.000Z",
    "dateTo": "2019-06-20T00:30:00.000Z",
    "dpo_qualityControl": "1",
    "dpo_resample": "none",
}
onc.orderDataProduct(params, includeMetadataFile=False)

The filters above include codes for location, deviceCategory, and dataProduct, as well as the file extension and a time interval (in UTC). They also include a couple of filters to configure this specific data product type (starting with the "dpo_" prefix), which can be obtained from the Data Product Options documentation. You can download more than 120 different types of data products including audio & video.

Check more on the data product download methods guide and code examples.

Obtaining sensor readings in (near) real-time

Another method to obtain ONC data is by directly obtaining a time series of sensor readings (available as soon as they reach our database).

In the following example, we obtain 5 seconds of conductivity readings from the CTD at Burrard Inlet:

params = {
    "locationCode": "BIIP",
    "deviceCategoryCode": "CTD",
    "propertyCode": "conductivity",
    "dateFrom": "2019-06-20T00:00:00.000Z",
    "dateTo": "2019-06-20T00:00:05.000Z",
}
onc.getScalardata(params)

# Longer method name
# onc.getScalardataByLocation(params)

The result includes matching lists of "values" and "sampleTimes" (increases performance for long time ranges). We also use the property code "conductivity" to limit results to a specific property available in this CTD.

Check more on the near real-time data access methods guide and code examples.

Downloading archived files

ONC scripts auto-generate and archive data products of different types at set time intervals. You can directly download these data product files from our files archive, as long as you know their unique filename.

In the following example, we get a list of archived files available for a camera at Ridley Island (in a certain time span), and download one of the files:

params = {
    "locationCode": "RISS",
    "deviceCategoryCode": "VIDEOCAM",
    "dateFrom": "2016-12-01T00:00:00.000Z",
    "dateTo": "2016-12-01T00:05:00.000Z",
}
result = onc.getArchivefile(params, allPages=True)

# Longer method name
# result = onc.getArchivefileByLocation(params, allPages=True)

# Download one of the files from result["files"]
onc.downloadArchivefile("AXISQ6044PTZACCC8E334C53_20161201T000001.000Z.jpg", overwrite=True)

You can use the method downloadArchivefile() as above to download individual files or the method downloadDirectArchivefile() to download all the files that match your filters.

Alternatively, if you prefer using a download manager like aria2 or Free Download Manager, getArchivefileUrls and getArchivefileUrl can return the download URLs of the archivefile without downloading the files.

Check more on the archive file download methods guide and code examples.

Documentation

The client library documentation is hosted on GitHub Pages. For documentation and examples about Oceans 3.0 API, visit the wiki and OpenAPI page on the Oceans 3.0 Data Portal website.

Multithreading issue

We kindly ask users to not use too many threads when using threading/multiprocessing libraries on download tasks. It can cause issues for both server and client and may not appreciably increase download speeds.

Contributing

All contributions are welcome and appreciated! Please refer to the Contributing guide before submitting any issues or pull requests.

Release files for onc 2.6.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 onc 2.6.0
File Size Uploaded
onc-2.6.0.tar.gz 39.8 kB Details

Built distribution (wheel)

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

Total release size: 79.8 kB

Release files / onc-2.6.0.tar.gz

Download URL onc-2.6.0.tar.gz
Size 39.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d36db8e361363f1e68941a589e9dc1365c12abb01dc7e327c2cc704f24212ba7
BLAKE2b-256 checksum
How to use checksums
59e8818b9ebc45fd13fed01e1237e1cfa2b2476206a60e0753ba45536bea0e86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2025.

Transparency log

Release files / onc-2.6.0-py3-none-any.whl

Download URL onc-2.6.0-py3-none-any.whl
Size 40.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5135b2ff92b0b1661b1c4f2eef24a40b02dfcb421152f9c328ed3fa4f72b6ea8
BLAKE2b-256 checksum
How to use checksums
55e026bd99a5971a09b2f080528c96182628114be156ed20b82bca9c20d2000a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

2.6.0 This release

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.5

2 release files

2.3.4

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0

2 release files

1.25.4

2 release files

1.25.3

2 release files

1.25.2

2 release files

1.25

1 release file

1.24

1 release file

1.23

1 release file

1.22

1 release file

1.21

1 release file

1.19

1 release file

1.18

1 release file

1.17

1 release file

1.16

1 release file

1.15

1 release file

1.14

1 release file

1.13

1 release file

1.0

3 release files

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