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:
| Access | Purpose |
|---|---|
ocean.integration_config | User configuration from spec.yaml / env (camelCase keys). |
ocean.config | Full Ocean settings object. |
ocean.port_client | Client Ocean uses to talk to Port's API. |
ocean.router | FastAPI router for custom HTTP routes under the integration. |
ocean.on_resync | Decorator to register resync handlers. |
ocean.on_start | Decorator for startup hooks. |
ocean.on_probe | Decorator for connection probe checks. |
ocean.add_webhook_processor | Register a live event processor. |
ocean.register_action_executor | Register an action executor. |
ocean.event_listener_type | Active 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).
| Access | Purpose |
|---|---|
event.type | Event type (for example resync, start, http_request). |
event.trigger_type | How the event was triggered (for example manual, machine, request). |
event.resource_config | Mapping entry for the current kind during a resync. |
event.port_app_config | Full Port app config for the resync. |
event.attributes | Per-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