Skip to content

models

Api

Bases: BaseModel

Data representing a particular ratelimit.

Source code in unkey/models/apis.py
@attrs.define(init=False, weakref_slot=False)
class Api(BaseModel):
    """Data representing a particular ratelimit."""

    id: str
    """The id for this api."""

    name: str
    """The name of the api."""

    workspace_id: str
    """The id for the workspace this api belongs to."""

id instance-attribute

id: str

The id for this api.

name instance-attribute

name: str

The name of the api.

workspace_id instance-attribute

workspace_id: str

The id for the workspace this api belongs to.

ApiKey

Bases: BaseModel

Minimal representation of an api key.

Source code in unkey/models/keys.py
@attrs.define(init=False, weakref_slot=False)
class ApiKey(BaseModel):
    """Minimal representation of an api key."""

    key_id: str
    """The id of this key stored at unkey."""

    key: str
    """The api key itself."""

key instance-attribute

key: str

The api key itself.

key_id instance-attribute

key_id: str

The id of this key stored at unkey.

ApiKeyList

Bases: BaseModel

Data representing keys for an api.

Source code in unkey/models/apis.py
@attrs.define(init=False, weakref_slot=False)
class ApiKeyList(BaseModel):
    """Data representing keys for an api."""

    keys: t.List[ApiKeyMeta]
    """A list of keys associated with the api."""

    total: int
    """The total number of keys associated with the api."""

keys instance-attribute

keys: t.List[ApiKeyMeta]

A list of keys associated with the api.

total instance-attribute

total: int

The total number of keys associated with the api.

ApiKeyMeta

Bases: BaseModel

Metadata about an api key.

Source code in unkey/models/keys.py
@attrs.define(init=False, weakref_slot=False)
class ApiKeyMeta(BaseModel):
    """Metadata about an api key."""

    id: str
    """The id of this key."""

    api_id: str
    """The id of the api this key belongs to."""

    workspace_id: str
    """The id of the workspace this key belongs to."""

    start: str
    """The prefix and beginning 3 letters of the key."""

    created_at: int
    """The unix epoch representing when this key was created in
    milliseconds."""

    owner_id: t.Optional[str]
    """The owner of this api key if one was specified."""

    expires: t.Optional[int]
    """The optional unix epoch representing when this key expires in
    milliseconds."""

    ratelimit: t.Optional[Ratelimit]
    """The optional ratelimit associated with this key."""

    meta: t.Optional[t.Dict[str, t.Any]]
    """The dynamic mapping of data used during key creation, if
    the key was found.
    """

api_id instance-attribute

api_id: str

The id of the api this key belongs to.

created_at instance-attribute

created_at: int

The unix epoch representing when this key was created in milliseconds.

expires instance-attribute

expires: t.Optional[int]

The optional unix epoch representing when this key expires in milliseconds.

id instance-attribute

id: str

The id of this key.

meta instance-attribute

meta: t.Optional[t.Dict[str, t.Any]]

The dynamic mapping of data used during key creation, if the key was found.

owner_id instance-attribute

owner_id: t.Optional[str]

The owner of this api key if one was specified.

ratelimit instance-attribute

ratelimit: t.Optional[Ratelimit]

The optional ratelimit associated with this key.

start instance-attribute

start: str

The prefix and beginning 3 letters of the key.

workspace_id instance-attribute

workspace_id: str

The id of the workspace this key belongs to.

ApiKeyVerification

Bases: BaseModel

Data about whether this api key is valid.

Source code in unkey/models/keys.py
@attrs.define(init=False, weakref_slot=False)
class ApiKeyVerification(BaseModel):
    """Data about whether this api key is valid."""

    valid: bool
    """Whether or not this key is valid and passes ratelimit."""

    owner_id: t.Optional[str]
    """The id of the owner for this key, if the key was found."""

    meta: t.Optional[t.Dict[str, t.Any]]
    """Dynamic mapping of data used during key creation, if the
    key was found.
    """

    error: t.Optional[str]
    """The error message if the key was invalid."""

error instance-attribute

error: t.Optional[str]

The error message if the key was invalid.

meta instance-attribute

meta: t.Optional[t.Dict[str, t.Any]]

Dynamic mapping of data used during key creation, if the key was found.

owner_id instance-attribute

owner_id: t.Optional[str]

The id of the owner for this key, if the key was found.

valid instance-attribute

valid: bool

Whether or not this key is valid and passes ratelimit.

BaseEnum

Bases: Enum

The base enum all library enums inherit from.

Source code in unkey/models/base.py
class BaseEnum(Enum):
    """The base enum all library enums inherit from."""

    __slots__ = ()

    value: str  # pyright: ignore

    def __str__(self) -> str:
        return self.value

    @classmethod
    def from_str(cls: t.Type[T], value: str) -> T:
        """Generate this enum from the given value.

        Args:
            value: The value to generate from.

        Returns:
            The generated enum.
        """
        try:
            return cls(value)
        except ValueError as e:
            raise ValueError(
                f"{e} variant. Please report this issue on github at "
                "https://github.com/Jonxslays/unkey.py/issues/new"
            ) from None

    @classmethod
    def from_str_maybe(cls: t.Type[T], value: str) -> t.Optional[T]:
        """Attempt to generate this enum from the given value.

        Args:
            value: The value to generate from.

        Returns:
            The generated enum or `None` if the value was not a valid
                enum variant.
        """
        try:
            return cls(value)
        except ValueError:
            return None

from_str classmethod

from_str(value: str) -> T

Generate this enum from the given value.

Parameters:

Name Type Description Default
value str

The value to generate from.

required

Returns:

Type Description
T

The generated enum.

Source code in unkey/models/base.py
@classmethod
def from_str(cls: t.Type[T], value: str) -> T:
    """Generate this enum from the given value.

    Args:
        value: The value to generate from.

    Returns:
        The generated enum.
    """
    try:
        return cls(value)
    except ValueError as e:
        raise ValueError(
            f"{e} variant. Please report this issue on github at "
            "https://github.com/Jonxslays/unkey.py/issues/new"
        ) from None

from_str_maybe classmethod

from_str_maybe(value: str) -> t.Optional[T]

Attempt to generate this enum from the given value.

Parameters:

Name Type Description Default
value str

The value to generate from.

required

Returns:

Type Description
t.Optional[T]

The generated enum or None if the value was not a valid enum variant.

Source code in unkey/models/base.py
@classmethod
def from_str_maybe(cls: t.Type[T], value: str) -> t.Optional[T]:
    """Attempt to generate this enum from the given value.

    Args:
        value: The value to generate from.

    Returns:
        The generated enum or `None` if the value was not a valid
            enum variant.
    """
    try:
        return cls(value)
    except ValueError:
        return None

BaseModel

The base model all library models inherit from.

Source code in unkey/models/base.py
@attrs.define(weakref_slot=False)
class BaseModel:
    """The base model all library models inherit from."""

    def to_dict(self) -> t.Dict[str, t.Any]:
        """Converts this class into a dictionary.

        Returns:
            The requested dictionary.
        """
        return attrs.asdict(self)

to_dict

to_dict() -> t.Dict[str, t.Any]

Converts this class into a dictionary.

Returns:

Type Description
t.Dict[str, t.Any]

The requested dictionary.

Source code in unkey/models/base.py
def to_dict(self) -> t.Dict[str, t.Any]:
    """Converts this class into a dictionary.

    Returns:
        The requested dictionary.
    """
    return attrs.asdict(self)

HttpResponse

Bases: BaseModel

Directly represents a response from the api.

Could indicate either success or failure.

Source code in unkey/models/http.py
@attrs.define(weakref_slot=False)
class HttpResponse(BaseModel):
    """Directly represents a response from the api.

    Could indicate either success or failure.
    """

    status: int
    """The HTTP status code."""

    message: str
    """The error or success message."""

message instance-attribute

message: str

The error or success message.

status instance-attribute

status: int

The HTTP status code.

Ratelimit

Bases: BaseModel

Data representing a particular ratelimit.

Source code in unkey/models/keys.py
@attrs.define(weakref_slot=False)
class Ratelimit(BaseModel):
    """Data representing a particular ratelimit."""

    type: RatelimitType
    """The type of ratelimiting to implement."""

    limit: int
    """The total amount of burstable requests."""

    refill_rate: int
    """How many tokens to refill during each refill interval."""

    refill_interval: int
    """The speed at which tokens are refilled."""

limit instance-attribute

limit: int

The total amount of burstable requests.

refill_interval instance-attribute

refill_interval: int

The speed at which tokens are refilled.

refill_rate instance-attribute

refill_rate: int

How many tokens to refill during each refill interval.

type instance-attribute

type: RatelimitType

The type of ratelimiting to implement.