|
| 1 | +from typing import Optional |
| 2 | +from pinecone.openapi_support import ApiClient |
| 3 | +from pinecone.core.openapi.admin.apis import OrganizationsApi |
| 4 | +from pinecone.utils import require_kwargs, parse_non_empty_args |
| 5 | +from pinecone.core.openapi.admin.models import UpdateOrganizationRequest |
| 6 | + |
| 7 | + |
| 8 | +class OrganizationResource: |
| 9 | + """ |
| 10 | + This class is used to list, fetch, and update organizations. |
| 11 | +
|
| 12 | + .. note:: |
| 13 | + The class should not be instantiated directly. Instead, access this classes |
| 14 | + methods through the :class:`pinecone.Admin` class's |
| 15 | + :attr:`organization` or :attr:`organizations` attributes. |
| 16 | +
|
| 17 | + .. code-block:: python |
| 18 | +
|
| 19 | + from pinecone import Admin |
| 20 | +
|
| 21 | + admin = Admin() |
| 22 | + organization = admin.organization.get(organization_id="my-organization-id") |
| 23 | + """ |
| 24 | + |
| 25 | + def __init__(self, api_client: ApiClient): |
| 26 | + """ |
| 27 | + Initialize the OrganizationResource. |
| 28 | +
|
| 29 | + .. warning:: |
| 30 | + This class should not be instantiated directly. Instead, access this classes |
| 31 | + methods through the :class:`pinecone.Admin` class's |
| 32 | + :attr:`organization` or :attr:`organizations` attributes. |
| 33 | +
|
| 34 | + :param api_client: The API client to use. |
| 35 | + :type api_client: ApiClient |
| 36 | + """ |
| 37 | + self._organizations_api = OrganizationsApi(api_client=api_client) |
| 38 | + self._api_client = api_client |
| 39 | + |
| 40 | + @require_kwargs |
| 41 | + def list(self): |
| 42 | + """ |
| 43 | + List all organizations associated with the account. |
| 44 | +
|
| 45 | + :return: An object with a list of organizations. |
| 46 | + :rtype: {"data": [Organization]} |
| 47 | +
|
| 48 | + Examples |
| 49 | + -------- |
| 50 | +
|
| 51 | + .. code-block:: python |
| 52 | + :caption: List all organizations |
| 53 | + :emphasize-lines: 8 |
| 54 | +
|
| 55 | + from pinecone import Admin |
| 56 | +
|
| 57 | + # Credentials read from PINECONE_CLIENT_ID and |
| 58 | + # PINECONE_CLIENT_SECRET environment variables |
| 59 | + admin = Admin() |
| 60 | +
|
| 61 | + # List all organizations |
| 62 | + organizations_response = admin.organization.list() |
| 63 | + for organization in organizations_response.data: |
| 64 | + print(organization.id) |
| 65 | + print(organization.name) |
| 66 | + print(organization.plan) |
| 67 | + print(organization.payment_status) |
| 68 | + """ |
| 69 | + return self._organizations_api.list_organizations() |
| 70 | + |
| 71 | + @require_kwargs |
| 72 | + def fetch(self, organization_id: str): |
| 73 | + """ |
| 74 | + Fetch an organization by organization_id. |
| 75 | +
|
| 76 | + :param organization_id: The organization_id of the organization to fetch. |
| 77 | + :type organization_id: str |
| 78 | + :return: The organization. |
| 79 | + :rtype: Organization |
| 80 | +
|
| 81 | + Examples |
| 82 | + -------- |
| 83 | +
|
| 84 | + .. code-block:: python |
| 85 | + :caption: Fetch an organization by organization_id |
| 86 | + :emphasize-lines: 7-9 |
| 87 | +
|
| 88 | + from pinecone import Admin |
| 89 | +
|
| 90 | + # Credentials read from PINECONE_CLIENT_ID and |
| 91 | + # PINECONE_CLIENT_SECRET environment variables |
| 92 | + admin = Admin() |
| 93 | +
|
| 94 | + organization = admin.organization.fetch( |
| 95 | + organization_id="42ca341d-43bf-47cb-9f27-e645dbfabea6" |
| 96 | + ) |
| 97 | + print(organization.id) |
| 98 | + print(organization.name) |
| 99 | + print(organization.plan) |
| 100 | + print(organization.payment_status) |
| 101 | + print(organization.created_at) |
| 102 | + print(organization.support_tier) |
| 103 | +
|
| 104 | + """ |
| 105 | + return self._organizations_api.fetch_organization(organization_id=organization_id) |
| 106 | + |
| 107 | + @require_kwargs |
| 108 | + def get(self, organization_id: str): |
| 109 | + """Alias for :func:`fetch` |
| 110 | +
|
| 111 | + Examples |
| 112 | + -------- |
| 113 | +
|
| 114 | + .. code-block:: python |
| 115 | + :caption: Get an organization by organization_id |
| 116 | + :emphasize-lines: 7-9 |
| 117 | +
|
| 118 | + from pinecone import Admin |
| 119 | +
|
| 120 | + # Credentials read from PINECONE_CLIENT_ID and |
| 121 | + # PINECONE_CLIENT_SECRET environment variables |
| 122 | + admin = Admin() |
| 123 | +
|
| 124 | + organization = admin.organization.get( |
| 125 | + organization_id="42ca341d-43bf-47cb-9f27-e645dbfabea6" |
| 126 | + ) |
| 127 | + print(organization.id) |
| 128 | + print(organization.name) |
| 129 | + """ |
| 130 | + return self.fetch(organization_id=organization_id) |
| 131 | + |
| 132 | + @require_kwargs |
| 133 | + def describe(self, organization_id: str): |
| 134 | + """Alias for :func:`fetch` |
| 135 | +
|
| 136 | + Examples |
| 137 | + -------- |
| 138 | +
|
| 139 | + .. code-block:: python |
| 140 | + :caption: Describe an organization by organization_id |
| 141 | + :emphasize-lines: 7-9 |
| 142 | +
|
| 143 | + from pinecone import Admin |
| 144 | +
|
| 145 | + # Credentials read from PINECONE_CLIENT_ID and |
| 146 | + # PINECONE_CLIENT_SECRET environment variables |
| 147 | + admin = Admin() |
| 148 | +
|
| 149 | + organization = admin.organization.describe( |
| 150 | + organization_id="42ca341d-43bf-47cb-9f27-e645dbfabea6" |
| 151 | + ) |
| 152 | + print(organization.id) |
| 153 | + print(organization.name) |
| 154 | + """ |
| 155 | + return self.fetch(organization_id=organization_id) |
| 156 | + |
| 157 | + @require_kwargs |
| 158 | + def update(self, organization_id: str, name: Optional[str] = None): |
| 159 | + """ |
| 160 | + Update an organization. |
| 161 | +
|
| 162 | + :param organization_id: The organization_id of the organization to update. |
| 163 | + :type organization_id: str |
| 164 | + :param name: The new name for the organization. If omitted, the name will not be updated. |
| 165 | + :type name: Optional[str] |
| 166 | + :return: The updated organization. |
| 167 | + :rtype: Organization |
| 168 | +
|
| 169 | + Examples |
| 170 | + -------- |
| 171 | +
|
| 172 | + .. code-block:: python |
| 173 | + :caption: Update an organization's name |
| 174 | + :emphasize-lines: 7-10 |
| 175 | +
|
| 176 | + from pinecone import Admin |
| 177 | +
|
| 178 | + # Credentials read from PINECONE_CLIENT_ID and |
| 179 | + # PINECONE_CLIENT_SECRET environment variables |
| 180 | + admin = Admin() |
| 181 | +
|
| 182 | + organization = admin.organization.update( |
| 183 | + organization_id="42ca341d-43bf-47cb-9f27-e645dbfabea6", |
| 184 | + name="updated-organization-name" |
| 185 | + ) |
| 186 | + print(organization.name) |
| 187 | +
|
| 188 | + """ |
| 189 | + args = [("name", name)] |
| 190 | + update_request = UpdateOrganizationRequest(**parse_non_empty_args(args)) |
| 191 | + return self._organizations_api.update_organization( |
| 192 | + organization_id=organization_id, update_organization_request=update_request |
| 193 | + ) |
0 commit comments