# my_integrations.py
from erdo.integrations import IntegrationConfig
from erdo import (
IntegrationType,
AuthType,
IntegrationStatus,
UIConfig,
IconConfig,
CodegenDetails,
CredentialField,
)
# PostgreSQL Database Integration
postgresql_config = IntegrationConfig(
name="PostgreSQL",
key="postgresql",
type=IntegrationType.DATABASE,
auth_types=[AuthType.DATABASE],
status=IntegrationStatus.ACTIVE,
description="PostgreSQL database for comprehensive data analysis and querying",
provider_name="PostgreSQL",
documentation_url="https://www.postgresql.org/docs/",
# Credential schema - defines what credentials are needed
credential_schema={
"host": CredentialField(
type="string",
description="Database host",
required=True,
source="integration_credentials"
),
"port": CredentialField(
type="string",
description="Database port",
required=True,
source="integration_credentials"
),
"database": CredentialField(
type="string",
description="Database name",
required=True,
source="integration_credentials"
),
"username": CredentialField(
type="string",
description="Database username",
required=True,
source="integration_credentials"
),
"password": CredentialField(
type="string",
description="Database password",
required=True,
source="integration_credentials"
),
},
# UI configuration for the Erdo interface
ui_config=UIConfig(
brand_logo_icon=IconConfig(set="tabler", name="database"),
brand_color="#336791",
button_style="blue"
),
# Code generation template for agents
codegen_details=CodegenDetails(
code='''import psycopg2
import pandas as pd
# Connect to PostgreSQL
conn = psycopg2.connect(
host=SECRETS["postgresql"]["host"],
port=SECRETS["postgresql"]["port"],
database=SECRETS["postgresql"]["database"],
user=SECRETS["postgresql"]["username"],
password=SECRETS["postgresql"]["password"]
)
# Example: Query data
df = pd.read_sql("SELECT * FROM your_table LIMIT 10", conn)
print(df)
conn.close()''',
imports=["psycopg2", "pandas"],
hint="Use psycopg2 to connect to PostgreSQL and pandas for data analysis. Connection details are configured automatically."
)
)
# Google Sheets OAuth2 Integration
google_sheets_config = IntegrationConfig(
name="Google Sheets",
key="google_sheets",
type=IntegrationType.API,
auth_types=[AuthType.OAUTH2],
status=IntegrationStatus.ACTIVE,
description="Connect to Google Sheets for data analysis and reporting.",
provider_name="Google",
documentation_url="https://developers.google.com/sheets/api/guides/concepts",
# OAuth2 configuration
auth_url="https://accounts.google.com/o/oauth2/v2/auth",
token_url="https://oauth2.googleapis.com/token",
available_scopes=[
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/spreadsheets.readonly"
],
scope_separator=" ",
# Credential schema
credential_schema={
"access_token": CredentialField(
type="string",
description="OAuth access token",
required=True,
source="integration_credentials"
),
"refresh_token": CredentialField(
type="string",
description="OAuth refresh token",
required=False,
source="integration_credentials"
),
"spreadsheet_id": CredentialField(
type="string",
description="Google Sheets spreadsheet ID",
required=True,
source="dataset_parameters"
),
},
# UI configuration
ui_config=UIConfig(
brand_logo_icon=IconConfig(set="custom", name="google-sheets"),
brand_color="#0F9D58",
button_style="white"
),
# Code generation
codegen_details=CodegenDetails(
code='''from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
def get_sheets_client(secret):
credentials = Credentials(token=secret['access_token'])
return build('sheets', 'v4', credentials=credentials)
# Example usage:
client = get_sheets_client(SECRETS["google_sheets"])
spreadsheet_id = PARAMETERS['google_sheets']['spreadsheet_id']
result = client.spreadsheets().values().get(
spreadsheetId=spreadsheet_id,
range='Sheet1!A1:Z1000'
).execute()
values = result.get('values', [])''',
imports=[
"from googleapiclient.discovery import build",
"from google.oauth2.credentials import Credentials"
]
)
)
# Export the integration configs for Erdo to discover
integration_configs = [
postgresql_config,
google_sheets_config,
]