âī¸ Update Integration Code
This section outlines the structure of a brand new integration, as well as provide some standards and practices to add your own custom logic to the integration.
Integration folder structureâ
After scaffolding a new integration (using the ocean new
command), a new directory with the integration name you provided will be created, it will have the following structure:
âââ my_new_integration
âââ tests
â  âââ __init__.py
âââ pyproject.toml
âââ poetry.toml
âââ main.py
âââ debug.py
âââ config.yaml
âââ changelog
âââ README.md
âââ Makefile
âââ Dockerfile
âââ CHANGELOG.md
Let's go over some important files and how to use them during the integration's development.
main.py
- run an integrationâ
This file serves as the entrypoint for the integration logic, when you scaffold a new integration it will already contain placeholders that guide you how and where in the code to implement your logic.
Of course since this file is only the entrypoint, you can add as many other .py
files as needed and construct your own directory structure including classes and modules when developing your integration.
When running the command ocean sail
, the Ocean CLI triggers a run of the integration using the main.py
file, after loading all of the necessary context and resources required by the Ocean framework.
debug.py
- debug an integrationâ
This file is used to trigger a local development run of the integration, it is useful to debug your integration and examine its execution through your IDE or preferred Python debugging interface.
In most cases you should not change this file, only use it as the target for your debug execution of the integration.
pyproject.toml
â
This file is used for the following main goals:
- Maintain the integration's current version via the
version
field. Should be bumped when a new version of the integration is released - Maintains the list of dependencies required by the integration, should be updated when new dependencies are added to the integration using the
poetry
CLI - Stores the configuration for automated tools that ensure consistent code quality for every developed integration. These
include
mypy
,ruff
andblack
. In addition it includes the setup fortowncrier
to maintain a proper CHANGELOG for the integration.
Add dependencies to the integrationâ
It is very common that an integration needs to make HTTP requests or utilize some 3rd-party library to perform its unique logic. This means the integration requires additional dependencies during its runtime.
Ocean framework integrations use Poetry to manage their dependencies, you can refer to the Poetry website for the CLI reference and documentation, here are some common commands:
poetry install
- install all dependencies listed in thepyproject.toml
file in the virtual env of the integrationpoetry add X
- add the specified package to the list of dependencies required by the integration (and also install it)poetry add -D x
- add the specified package to the list of dev dependencies used during the integration's development (and also install it)
poetry remove X
- remove the specified package from the list of dependencies used by the integration