Skip to main content

Python wrapper for the Sea Around Us fisheries catch API

Project description

py-seaaroundus

PyPI version Python versions

Python wrapper for the Sea Around Us API, inspired by the R rseaaroundus package. Install as py-seaaroundus; import as seaaroundus.

Install from PyPI:

pip install py-seaaroundus

Optional extras:

pip install "py-seaaroundus[plot]"     # matplotlib stacked-area charts
pip install "py-seaaroundus[maps]"     # geopandas region maps
pip install "py-seaaroundus[notebook]" # ipykernel for notebooks
pip install "py-seaaroundus[all]"      # plot, maps, and dev tools

The Sea Around Us data are licensed to the public under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License. Please read the data use policy in DATA_USE.

Quick start

import seaaroundus as sau

# List exclusive economic zones
eezs = sau.list_regions("eez")

# Catch data for Brazil (EEZ id 76) as a wide year-by-species table
catch = sau.catch_data("eez", 76)

# Top 3 taxa only
catch_top3 = sau.catch_data("eez", 76, limit=3)

# Value by reporting status
value = sau.catch_data("eez", 76, measure="value", dimension="reporting-status")

# Long/tidy format (useful for ggplot-style workflows)
long = sau.catch_data_long("eez", 76, dimension="functionalgroup")

# Marine trophic index (deprecated: endpoint currently returns HTTP 500)
mti = sau.marine_trophic_index("eez", 76)
fib = sau.marine_trophic_index("eez", 76, mti_type="fib_index", transfer_efficiency=0.25)

# Global EEZ vs. high-seas percentages (deprecated: endpoint currently unavailable)
global_split = sau.eez_vs_high_seas()

# Spatial cell queries (deprecated: endpoints currently return HTTP 403)
cells = sau.get_cells(
    "POLYGON ((-48.17 15.84, -54.96 28.96, -35.96 27.60, -48.17 15.84))"
)
cell_catch = sau.get_cell_data(cells, year=2005)

Plotting and maps

import seaaroundus as sau

fig, ax = sau.plot_catch_data("eez", 76, measure="tonnage", dimension="taxon")
fig, ax = sau.plot_mti("eez", 76)
fig, ax = sau.region_map("eez", 76)

Batch downloads for multiple countries

import pandas as pd
import seaaroundus as sau

countries = pd.DataFrame(
    {
        "iso_a3": ["BRA", "IDN"],
        "country": ["Brazil", "Indonesia"],
    }
)

totals = sau.download_country_fisheries_timeseries(
    countries,
    years=10,
    measure="value",
    show_progress=True,
)

breakdown = sau.download_country_fisheries_breakdown(
    countries,
    dimension="functionalgroup",
    measure="value",
)

API reference

Python R equivalent Description
list_regions(region) listregions() List region IDs and titles
list_fishing_entities() List fishing countries/territories
catch_data(...) catchdata() Wide catch table (years × categories)
catch_data_long(...) Long/tidy catch table
region_map(region, id=...) regionmap() Region map (requires [maps])
plot_catch_data(...) catchdata(..., chart=TRUE) Stacked area chart
marine_trophic_index(...) marinetrophicindex() Deprecated: endpoint currently returns HTTP 500
eez_vs_high_seas() eezsvshighseas() Deprecated: endpoint currently times out/unavailable
get_cells(shape) getcells() Deprecated: endpoint currently returns HTTP 403
get_cell_data(cells, year=...) getcelldata() Deprecated: endpoint currently returns HTTP 403
plot_mti(...) marinetrophicindex(..., chart=TRUE) Deprecated: depends on deprecated MTI endpoint
plot_eez_vs_high_seas() eezsvshighseas(chart=TRUE) Deprecated: depends on unavailable endpoint

Regions

  • eez
  • lme
  • rfmo
  • eez-bordering
  • taxon
  • fishing-entity

Measures

  • tonnage — reconstructed catch in metric tonnes
  • value — real 2005 million US dollars

Dimensions

  • taxon (not available for the taxon region type)
  • commercialgroup
  • functionalgroup
  • country (fishing country)
  • sector
  • catchtype
  • reporting-status
  • layer
  • eez (only for eez-bordering and taxon regions)
  • highseas (only for taxon region)

Reconstructed catch is currently available through 2019.

Endpoint availability notes

The Sea Around Us public API is upstream and may change without notice. As of the latest probe in this repository:

  • /api/v1/eez/marine-trophic-index/ returns HTTP 500
  • /api/v1/global/eez-vs-high-seas/ is timing out
  • /api/v1/spatial/r/shape returns HTTP 403
  • /api/v1/spatial/r/cells returns HTTP 403

Related wrapper functions are marked deprecated in code and README until (and if) these endpoints are restored.

Custom client

from seaaroundus import SeaAroundUsClient, catch_data

client = SeaAroundUsClient(
    base_url="http://api.seaaroundus.org/api/v1",
    request_source="my-research-project",
    timeout=60,
)
catch = catch_data("eez", 76, client=client)

Usage note

When querying the API, please be respectful of the resources required to provide this data. Cache results locally (handled by the repository's default behaviour) and avoid repeated requests for duplicate information.

Development

Clone the repository and install in editable mode:

git clone https://github.com/orlando-code/py-seaaroundus.git
cd py-seaaroundus
pip install -e ".[dev]"
pre-commit install   # run ruff + pytest on each commit
pytest               # run tests manually

CI runs the same checks on push and pull requests via GitHub Actions.

License

See LICENSE for more information.

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

py_seaaroundus-1.0.2.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_seaaroundus-1.0.2-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file py_seaaroundus-1.0.2.tar.gz.

File metadata

  • Download URL: py_seaaroundus-1.0.2.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for py_seaaroundus-1.0.2.tar.gz
Algorithm Hash digest
SHA256 99c7d273de7a21acc3c5bcf3a1e7363db5e96d74c0eb0e3d90b85e6125fb884a
MD5 9fff5cd71211f089b2d41a7de905f27f
BLAKE2b-256 8e9144e10578f4c3c898ea47339936777022b88c14844e160005f79a92a952c6

See more details on using hashes here.

File details

Details for the file py_seaaroundus-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_seaaroundus-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for py_seaaroundus-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c0dfaabda7705e4de0a4e2854140ad6b609ac4438c3681418d4e62fb03f40ab0
MD5 76d0bc78ed6496e467066e8f87df9277
BLAKE2b-256 7d9dd066d868da7579498ad4609944bde301e9349911fdd3c041631dd0190e89

See more details on using hashes here.

Supported by

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