LogoLogo
About
  • Home
  • Guides
  • BDK
  • REST API
  • BDK Overview
  • Planning Guide
  • Setup Guide
  • Development Guide
  • Deployment
  • Learning a BDK Book
  • Connection Commands
  • BDK API Reference
    • Concepts
    • Connections
    • Decorators
      • @book
      • @concept
      • @config
      • @connect
      • @oauth
      • @oauthtoken
      • @procedure
    • Docstrings
    • Enums
      • FilterBinaryOperator
      • FilterUnaryOperator
    • Filter Expressions
    • Noun Phrases
    • Procedures
Powered by GitBook
On this page
  • Overview
  • Syntax
  • Keyword Arguments
  • Implementation Example

Was this helpful?

Export as PDF
  1. BDK API Reference
  2. Decorators

@connect

Last updated 1 month ago

Was this helpful?

Overview

The @connect decorator is used to wrap functions that handle or authentication tasks. It defines the syntax for writing a , which instantiates the connection in Kognitos to the third-party API or service that's implemented in your Python function.

Syntax

@connect(*args, **kwargs)

Keyword Arguments

Argument
Type
Description

name

str

A name to associate with the connection. If not provided, it defaults to the function name.

noun_phrase

str

A unique label to identify the authentication method. If not provided, it will be inferred from the function name. Examples include, but are not limited to:

  • noun_phrase="api keys"

  • noun_phrase="client credentials"

  • noun_phrase="user password authentication"

Implementation Example

This is an example implementation of connecting to the OpenWeather API using an API key:

@connect(noun_phrase="api keys")
def connect(self, api_key: str):
  """
  Authenticate to Open Weather API using the specified API key. 
  You can obtain your own API key by visiting Open Weather's 
  website at https://openweathermap.org/appid.

  Arguments:
      api_key: The API key to be used for connecting

  Labels:
      api_key: API Key
  """
  api_key = os.getenv("API_KEY", api_key)
  test_url = f"{self._base_url}?appid={api_key}&q=London"
  response = requests.get(test_url, timeout=self._timeout)
  if response.status_code == 401:
      response_data = response.json()
      if "Invalid API key" in response_data.get("message", ""):
          raise ValueError("Invalid API key")

  self._api_key = api_key

Refer to for additional context and usage examples.

connections
connection command
connections