> For the complete documentation index, see llms.txt.
Skip to main content

Check out Port for yourself ➜ 

Ocean and event contexts

Ocean exposes two context objects you can import in integration code.

Ocean context​

Import ocean from port_ocean.context.ocean. Common attributes and helpers:

AccessPurpose
ocean.integration_configUser configuration from spec.yaml / env (camelCase keys).
ocean.configFull Ocean settings object.
ocean.port_clientClient Ocean uses to talk to Port's API.
ocean.routerFastAPI router for custom HTTP routes under the integration.
ocean.on_resyncDecorator to register resync handlers.
ocean.on_startDecorator for startup hooks.
ocean.on_probeDecorator for connection probe checks.
ocean.add_webhook_processorRegister a live event processor.
ocean.register_action_executorRegister an action executor.
ocean.event_listener_typeActive listener type (for example POLLING or ONCE).
from port_ocean.context.ocean import ocean
from port_ocean.core.ocean_types import ASYNC_GENERATOR_RESYNC_TYPE


@ocean.on_resync("project")
async def on_resync_projects(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
base_url = ocean.integration_config["apiBaseUrl"]
...

Event context​

Import event from port_ocean.context.event. It is available only while Ocean is handling an event (resync, start, or HTTP request).

AccessPurpose
event.typeEvent type (for example resync, start, http_request).
event.trigger_typeHow the event was triggered (for example manual, machine, request).
event.resource_configMapping entry for the current kind during a resync.
event.port_app_configFull Port app config for the resync.
event.attributesPer-event dict for caching shared lookups during that event.
from port_ocean.context.event import event

resource_config = event.resource_config
event_type = event.type