Skip to content

SerpAPIConfig

Base classes

Name Children Inherits
BaseSearchProviderConfig
searchly_config.configs
Base search provider configuration.

⋔ Inheritance diagram

graph TD
  1815518055["configs.SerpAPIConfig"]
  860522681["configs.BaseSearchProviderConfig"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  860522681 --> 1815518055
  330168112 --> 860522681
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: BaseSearchProviderConfig

SerpAPI provider configuration.

Uses SerpAPI for web and news search via Google. Full support for country, language, and location filtering.

Source code in src/searchly_config/configs.py
class SerpAPIConfig(BaseSearchProviderConfig):
    """SerpAPI provider configuration.

    Uses SerpAPI for web and news search via Google.
    Full support for country, language, and location filtering.
    """

    type: Literal["serpapi"] = Field("serpapi", init=False)
    """SerpAPI provider."""

    api_key: SecretStr | None = Field(default=None, title="API Key")
    """SerpAPI key. Defaults to SERPAPI_KEY env var."""

    def is_configured(self) -> bool:
        """Check if SerpAPI credentials are configured."""
        return self.api_key is not None or bool(os.getenv("SERPAPI_KEY"))

    def get_provider(self) -> AsyncSerpAPIClient:
        """Create SerpAPI provider instance."""
        from searchly.providers.serpapi_provider.client import AsyncSerpAPIClient

        api_key = self.api_key.get_secret_value() if self.api_key else None
        return AsyncSerpAPIClient(api_key=api_key)

api_key class-attribute instance-attribute

api_key: SecretStr | None = Field(default=None, title='API Key')

SerpAPI key. Defaults to SERPAPI_KEY env var.

type class-attribute instance-attribute

type: Literal['serpapi'] = Field('serpapi', init=False)

SerpAPI provider.

get_provider

get_provider() -> AsyncSerpAPIClient

Create SerpAPI provider instance.

Source code in src/searchly_config/configs.py
def get_provider(self) -> AsyncSerpAPIClient:
    """Create SerpAPI provider instance."""
    from searchly.providers.serpapi_provider.client import AsyncSerpAPIClient

    api_key = self.api_key.get_secret_value() if self.api_key else None
    return AsyncSerpAPIClient(api_key=api_key)

is_configured

is_configured() -> bool

Check if SerpAPI credentials are configured.

Source code in src/searchly_config/configs.py
def is_configured(self) -> bool:
    """Check if SerpAPI credentials are configured."""
    return self.api_key is not None or bool(os.getenv("SERPAPI_KEY"))

:fa-brands-github: Show source on GitHub