Skip to content

hololinked.client.security.APIKeySecurity

Bases: BaseModel

API Key Security Scheme.

The API key is added into a header named X-API-Key.

client = ClientFactory.http(
    url="http://localhost:9000/my-thing/resources/wot-td",
    security_scheme=APIKeySecurity(value=os.getenv("APIKEY", "default-api-key"))
)
Source code in repo/hololinked/hololinked/client/security.py
class APIKeySecurity(BaseModel):
    """
    API Key Security Scheme.

    The API key is added into a header named `X-API-Key`.

    ```python
    client = ClientFactory.http(
        url="http://localhost:9000/my-thing/resources/wot-td",
        security_scheme=APIKeySecurity(value=os.getenv("APIKEY", "default-api-key"))
    )
    ```
    """

    value: str
    """The API key value to use for authentication."""

    http_header_name: str = "X-API-Key"
    """
    Name of the HTTP header to use for authentication, default is `X-API-Key`.
    Override this if the server expects the API key in a different header.
    """

    @property
    def http_header(self) -> str:
        """Value for the API key header."""
        return self.value

Attributes

value instance-attribute

value: str

The API key value to use for authentication.

http_header_name class-attribute instance-attribute

http_header_name: str = 'X-API-Key'

Name of the HTTP header to use for authentication, default is X-API-Key. Override this if the server expects the API key in a different header.

http_header property

http_header: str

Value for the API key header.