Skip to content

organization

numerous.organization

Package for managing organizations.

Organization

Represents a Numerous platform organization.

Attributes:

Name Type Description
id str

The unique identifier for the organization.

slug str

The slug of the organization. Can be updated and cached to minimize API calls.

Source code in numerous/organization/organization.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Organization:
    """
    Represents a Numerous platform organization.

    Attributes:
        id (str): The unique identifier for the organization.
        slug (str): The slug of the organization. Can be updated and cached to
            minimize API calls.

    """

    id: str
    _client: Client
    _slug: str | None = None
    _last_update_time: float = 0.0

    def __init__(self, organization_id: str, _client: Client) -> None:
        self.id = organization_id
        self._client = _client

    @property
    def slug(self) -> str:
        """
        Get the organization slug.

        The slug is cached and updated at most once every 5 minutes.

        Returns:
            The organization slug.

        """
        current_time = time.time()
        if (
            self._slug is None
            or current_time - self._last_update_time > _UPDATE_INTERVAL_SECONDS
        ):
            org_data = self._client.get_organization(self.id)
            if org_data is None:
                raise OrganizationNotFoundError(organization_id=self.id)

            self._slug = org_data.slug
            self._last_update_time = current_time

        return self._slug

slug: str property

Get the organization slug.

The slug is cached and updated at most once every 5 minutes.

Returns:

Type Description
str

The organization slug.

organization_from_env(_client=None)

Create a Organization instance from environment variables.

Parameters:

Name Type Description Default
_client Optional[Client]

A client instance.

None

Returns:

Type Description
Organization

A new Organization instance created environment variables.

Source code in numerous/organization/factory.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def organization_from_env(_client: Optional[Client] = None) -> Organization:
    """
    Create a Organization instance from environment variables.

    Args:
        _client: A client instance.

    Returns:
        A new Organization instance created environment variables.

    """
    if _client is None:
        _client = get_client()

    organization_id = os.getenv("NUMEROUS_ORGANIZATION_ID")
    if organization_id is None:
        raise OrganizationIDMissingError

    return Organization(organization_id=organization_id, _client=_client)