| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing_extensions import Literal |
| 4 |
|
| 5 |
import httpx2 |
| 6 |
|
| 7 |
from ...._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given |
| 8 |
from ...._utils import path_template |
| 9 |
from ...._compat import cached_property |
| 10 |
from ...._resource import SyncAPIResource, AsyncAPIResource |
| 11 |
from ...._response import ( |
| 12 |
to_raw_response_wrapper, |
| 13 |
to_streamed_response_wrapper, |
| 14 |
async_to_raw_response_wrapper, |
| 15 |
async_to_streamed_response_wrapper, |
| 16 |
) |
| 17 |
from ....pagination import SyncPage, AsyncPage |
| 18 |
from ...._base_client import AsyncPaginator, make_request_options |
| 19 |
from ....types.beta.organization.user_remove_response import UserRemoveResponse |
| 20 |
from ....types.beta.organization.beta_organization_user import BetaOrganizationUser |
| 21 |
|
| 22 |
__all__ = ["Users", "AsyncUsers"] |
| 23 |
|
| 24 |
|
| 25 |
class Users(SyncAPIResource): |
| 26 |
@cached_property |
| 27 |
def with_raw_response(self) -> UsersWithRawResponse: |
| 28 |
""" |
| 29 |
This property can be used as a prefix for any HTTP method call to return |
| 30 |
the raw response object instead of the parsed content. |
| 31 |
|
| 32 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 33 |
""" |
| 34 |
return UsersWithRawResponse(self) |
| 35 |
|
| 36 |
@cached_property |
| 37 |
def with_streaming_response(self) -> UsersWithStreamingResponse: |
| 38 |
""" |
| 39 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 40 |
|
| 41 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 42 |
""" |
| 43 |
return UsersWithStreamingResponse(self) |
| 44 |
|
| 45 |
def retrieve( |
| 46 |
self, |
| 47 |
user_id: str, |
| 48 |
*, |
| 49 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 50 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 51 |
extra_headers: Headers | None = None, |
| 52 |
extra_query: Query | None = None, |
| 53 |
extra_body: Body | None = None, |
| 54 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 55 |
) -> BetaOrganizationUser: |
| 56 |
""" |
| 57 |
Retrieve a member of the organization by user ID. |
| 58 |
|
| 59 |
Args: |
| 60 |
user_id: ID of the User. |
| 61 |
|
| 62 |
extra_headers: Send extra headers |
| 63 |
|
| 64 |
extra_query: Add additional query parameters to the request |
| 65 |
|
| 66 |
extra_body: Add additional JSON properties to the request |
| 67 |
|
| 68 |
timeout: Override the client-level default timeout for this request, in seconds |
| 69 |
""" |
| 70 |
if not user_id: |
| 71 |
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") |
| 72 |
return self._get( |
| 73 |
path_template("/v1/organizations/users/{user_id}?beta=true", user_id=user_id), |
| 74 |
options=make_request_options( |
| 75 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 76 |
), |
| 77 |
cast_to=BetaOrganizationUser, |
| 78 |
) |
| 79 |
|
| 80 |
def update( |
| 81 |
self, |
| 82 |
user_id: str, |
| 83 |
*, |
| 84 |
role: Literal["billing", "claude_code_user", "developer", "managed", "user"], |
| 85 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 86 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 87 |
extra_headers: Headers | None = None, |
| 88 |
extra_query: Query | None = None, |
| 89 |
extra_body: Body | None = None, |
| 90 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 91 |
) -> BetaOrganizationUser: |
| 92 |
""" |
| 93 |
Update a member's organization role. |
| 94 |
|
| 95 |
Args: |
| 96 |
user_id: ID of the User. |
| 97 |
|
| 98 |
role: New role for the User. |
| 99 |
|
| 100 |
The accepted values depend on the organization type. Console and API |
| 101 |
organizations accept `user`, `developer`, `billing`, and `claude_code_user`; |
| 102 |
`admin` cannot be assigned through the API. Claude Enterprise organizations |
| 103 |
accept `user` and `managed`. |
| 104 |
|
| 105 |
extra_headers: Send extra headers |
| 106 |
|
| 107 |
extra_query: Add additional query parameters to the request |
| 108 |
|
| 109 |
extra_body: Add additional JSON properties to the request |
| 110 |
|
| 111 |
timeout: Override the client-level default timeout for this request, in seconds |
| 112 |
""" |
| 113 |
if not user_id: |
| 114 |
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") |
| 115 |
return self._post( |
| 116 |
path_template("/v1/organizations/users/{user_id}?beta=true", user_id=user_id), |
| 117 |
body={"role": role}, |
| 118 |
options=make_request_options( |
| 119 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 120 |
), |
| 121 |
cast_to=BetaOrganizationUser, |
| 122 |
) |
| 123 |
|
| 124 |
def list( |
| 125 |
self, |
| 126 |
*, |
| 127 |
after_id: str | Omit = omit, |
| 128 |
before_id: str | Omit = omit, |
| 129 |
email: str | Omit = omit, |
| 130 |
limit: int | Omit = omit, |
| 131 |
roles: SequenceNotStr[str] | Omit = omit, |
| 132 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 133 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 134 |
extra_headers: Headers | None = None, |
| 135 |
extra_query: Query | None = None, |
| 136 |
extra_body: Body | None = None, |
| 137 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 138 |
) -> SyncPage[BetaOrganizationUser]: |
| 139 |
""" |
| 140 |
List the organization's members. |
| 141 |
|
| 142 |
Args: |
| 143 |
after_id: ID of the object to use as a cursor for pagination. When provided, returns the |
| 144 |
page of results immediately after this object. |
| 145 |
|
| 146 |
before_id: ID of the object to use as a cursor for pagination. When provided, returns the |
| 147 |
page of results immediately before this object. |
| 148 |
|
| 149 |
email: Filter by user email. |
| 150 |
|
| 151 |
limit: Number of items to return per page. |
| 152 |
|
| 153 |
Defaults to `20`. Ranges from `1` to `1000`. |
| 154 |
|
| 155 |
roles: Filter to items whose `role` equals one of the supplied values. Repeatable; |
| 156 |
values are OR'ed together. |
| 157 |
|
| 158 |
Accepted values depend on the organization type: Console and API organizations |
| 159 |
accept `user`, `developer`, `billing`, `admin`, and `claude_code_user`; Claude |
| 160 |
Enterprise organizations accept `user`, `owner`, `primary_owner`, |
| 161 |
`membership_admin`, and `managed`. |
| 162 |
|
| 163 |
extra_headers: Send extra headers |
| 164 |
|
| 165 |
extra_query: Add additional query parameters to the request |
| 166 |
|
| 167 |
extra_body: Add additional JSON properties to the request |
| 168 |
|
| 169 |
timeout: Override the client-level default timeout for this request, in seconds |
| 170 |
""" |
| 171 |
return self._get_api_list( |
| 172 |
"/v1/organizations/users?beta=true", |
| 173 |
page=SyncPage[BetaOrganizationUser], |
| 174 |
options=make_request_options( |
| 175 |
extra_headers=extra_headers, |
| 176 |
extra_query=extra_query, |
| 177 |
extra_body=extra_body, |
| 178 |
timeout=timeout, |
| 179 |
query={ |
| 180 |
"after_id": after_id, |
| 181 |
"before_id": before_id, |
| 182 |
"email": email, |
| 183 |
"limit": limit, |
| 184 |
"roles": roles, |
| 185 |
}, |
| 186 |
), |
| 187 |
model=BetaOrganizationUser, |
| 188 |
) |
| 189 |
|
| 190 |
def remove( |
| 191 |
self, |
| 192 |
user_id: str, |
| 193 |
*, |
| 194 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 195 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 196 |
extra_headers: Headers | None = None, |
| 197 |
extra_query: Query | None = None, |
| 198 |
extra_body: Body | None = None, |
| 199 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 200 |
) -> UserRemoveResponse: |
| 201 |
""" |
| 202 |
Remove a member from the organization. |
| 203 |
|
| 204 |
Args: |
| 205 |
user_id: ID of the User. |
| 206 |
|
| 207 |
extra_headers: Send extra headers |
| 208 |
|
| 209 |
extra_query: Add additional query parameters to the request |
| 210 |
|
| 211 |
extra_body: Add additional JSON properties to the request |
| 212 |
|
| 213 |
timeout: Override the client-level default timeout for this request, in seconds |
| 214 |
""" |
| 215 |
if not user_id: |
| 216 |
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") |
| 217 |
return self._delete( |
| 218 |
path_template("/v1/organizations/users/{user_id}?beta=true", user_id=user_id), |
| 219 |
options=make_request_options( |
| 220 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 221 |
), |
| 222 |
cast_to=UserRemoveResponse, |
| 223 |
) |
| 224 |
|
| 225 |
|
| 226 |
class AsyncUsers(AsyncAPIResource): |
| 227 |
@cached_property |
| 228 |
def with_raw_response(self) -> AsyncUsersWithRawResponse: |
| 229 |
""" |
| 230 |
This property can be used as a prefix for any HTTP method call to return |
| 231 |
the raw response object instead of the parsed content. |
| 232 |
|
| 233 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 234 |
""" |
| 235 |
return AsyncUsersWithRawResponse(self) |
| 236 |
|
| 237 |
@cached_property |
| 238 |
def with_streaming_response(self) -> AsyncUsersWithStreamingResponse: |
| 239 |
""" |
| 240 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 241 |
|
| 242 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 243 |
""" |
| 244 |
return AsyncUsersWithStreamingResponse(self) |
| 245 |
|
| 246 |
async def retrieve( |
| 247 |
self, |
| 248 |
user_id: str, |
| 249 |
*, |
| 250 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 251 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 252 |
extra_headers: Headers | None = None, |
| 253 |
extra_query: Query | None = None, |
| 254 |
extra_body: Body | None = None, |
| 255 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 256 |
) -> BetaOrganizationUser: |
| 257 |
""" |
| 258 |
Retrieve a member of the organization by user ID. |
| 259 |
|
| 260 |
Args: |
| 261 |
user_id: ID of the User. |
| 262 |
|
| 263 |
extra_headers: Send extra headers |
| 264 |
|
| 265 |
extra_query: Add additional query parameters to the request |
| 266 |
|
| 267 |
extra_body: Add additional JSON properties to the request |
| 268 |
|
| 269 |
timeout: Override the client-level default timeout for this request, in seconds |
| 270 |
""" |
| 271 |
if not user_id: |
| 272 |
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") |
| 273 |
return await self._get( |
| 274 |
path_template("/v1/organizations/users/{user_id}?beta=true", user_id=user_id), |
| 275 |
options=make_request_options( |
| 276 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 277 |
), |
| 278 |
cast_to=BetaOrganizationUser, |
| 279 |
) |
| 280 |
|
| 281 |
async def update( |
| 282 |
self, |
| 283 |
user_id: str, |
| 284 |
*, |
| 285 |
role: Literal["billing", "claude_code_user", "developer", "managed", "user"], |
| 286 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 287 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 288 |
extra_headers: Headers | None = None, |
| 289 |
extra_query: Query | None = None, |
| 290 |
extra_body: Body | None = None, |
| 291 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 292 |
) -> BetaOrganizationUser: |
| 293 |
""" |
| 294 |
Update a member's organization role. |
| 295 |
|
| 296 |
Args: |
| 297 |
user_id: ID of the User. |
| 298 |
|
| 299 |
role: New role for the User. |
| 300 |
|
| 301 |
The accepted values depend on the organization type. Console and API |
| 302 |
organizations accept `user`, `developer`, `billing`, and `claude_code_user`; |
| 303 |
`admin` cannot be assigned through the API. Claude Enterprise organizations |
| 304 |
accept `user` and `managed`. |
| 305 |
|
| 306 |
extra_headers: Send extra headers |
| 307 |
|
| 308 |
extra_query: Add additional query parameters to the request |
| 309 |
|
| 310 |
extra_body: Add additional JSON properties to the request |
| 311 |
|
| 312 |
timeout: Override the client-level default timeout for this request, in seconds |
| 313 |
""" |
| 314 |
if not user_id: |
| 315 |
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") |
| 316 |
return await self._post( |
| 317 |
path_template("/v1/organizations/users/{user_id}?beta=true", user_id=user_id), |
| 318 |
body={"role": role}, |
| 319 |
options=make_request_options( |
| 320 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 321 |
), |
| 322 |
cast_to=BetaOrganizationUser, |
| 323 |
) |
| 324 |
|
| 325 |
def list( |
| 326 |
self, |
| 327 |
*, |
| 328 |
after_id: str | Omit = omit, |
| 329 |
before_id: str | Omit = omit, |
| 330 |
email: str | Omit = omit, |
| 331 |
limit: int | Omit = omit, |
| 332 |
roles: SequenceNotStr[str] | Omit = omit, |
| 333 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 334 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 335 |
extra_headers: Headers | None = None, |
| 336 |
extra_query: Query | None = None, |
| 337 |
extra_body: Body | None = None, |
| 338 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 339 |
) -> AsyncPaginator[BetaOrganizationUser, AsyncPage[BetaOrganizationUser]]: |
| 340 |
""" |
| 341 |
List the organization's members. |
| 342 |
|
| 343 |
Args: |
| 344 |
after_id: ID of the object to use as a cursor for pagination. When provided, returns the |
| 345 |
page of results immediately after this object. |
| 346 |
|
| 347 |
before_id: ID of the object to use as a cursor for pagination. When provided, returns the |
| 348 |
page of results immediately before this object. |
| 349 |
|
| 350 |
email: Filter by user email. |
| 351 |
|
| 352 |
limit: Number of items to return per page. |
| 353 |
|
| 354 |
Defaults to `20`. Ranges from `1` to `1000`. |
| 355 |
|
| 356 |
roles: Filter to items whose `role` equals one of the supplied values. Repeatable; |
| 357 |
values are OR'ed together. |
| 358 |
|
| 359 |
Accepted values depend on the organization type: Console and API organizations |
| 360 |
accept `user`, `developer`, `billing`, `admin`, and `claude_code_user`; Claude |
| 361 |
Enterprise organizations accept `user`, `owner`, `primary_owner`, |
| 362 |
`membership_admin`, and `managed`. |
| 363 |
|
| 364 |
extra_headers: Send extra headers |
| 365 |
|
| 366 |
extra_query: Add additional query parameters to the request |
| 367 |
|
| 368 |
extra_body: Add additional JSON properties to the request |
| 369 |
|
| 370 |
timeout: Override the client-level default timeout for this request, in seconds |
| 371 |
""" |
| 372 |
return self._get_api_list( |
| 373 |
"/v1/organizations/users?beta=true", |
| 374 |
page=AsyncPage[BetaOrganizationUser], |
| 375 |
options=make_request_options( |
| 376 |
extra_headers=extra_headers, |
| 377 |
extra_query=extra_query, |
| 378 |
extra_body=extra_body, |
| 379 |
timeout=timeout, |
| 380 |
query={ |
| 381 |
"after_id": after_id, |
| 382 |
"before_id": before_id, |
| 383 |
"email": email, |
| 384 |
"limit": limit, |
| 385 |
"roles": roles, |
| 386 |
}, |
| 387 |
), |
| 388 |
model=BetaOrganizationUser, |
| 389 |
) |
| 390 |
|
| 391 |
async def remove( |
| 392 |
self, |
| 393 |
user_id: str, |
| 394 |
*, |
| 395 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 396 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 397 |
extra_headers: Headers | None = None, |
| 398 |
extra_query: Query | None = None, |
| 399 |
extra_body: Body | None = None, |
| 400 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 401 |
) -> UserRemoveResponse: |
| 402 |
""" |
| 403 |
Remove a member from the organization. |
| 404 |
|
| 405 |
Args: |
| 406 |
user_id: ID of the User. |
| 407 |
|
| 408 |
extra_headers: Send extra headers |
| 409 |
|
| 410 |
extra_query: Add additional query parameters to the request |
| 411 |
|
| 412 |
extra_body: Add additional JSON properties to the request |
| 413 |
|
| 414 |
timeout: Override the client-level default timeout for this request, in seconds |
| 415 |
""" |
| 416 |
if not user_id: |
| 417 |
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") |
| 418 |
return await self._delete( |
| 419 |
path_template("/v1/organizations/users/{user_id}?beta=true", user_id=user_id), |
| 420 |
options=make_request_options( |
| 421 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 422 |
), |
| 423 |
cast_to=UserRemoveResponse, |
| 424 |
) |
| 425 |
|
| 426 |
|
| 427 |
class UsersWithRawResponse: |
| 428 |
def __init__(self, users: Users) -> None: |
| 429 |
self._users = users |
| 430 |
|
| 431 |
self.retrieve = to_raw_response_wrapper( |
| 432 |
users.retrieve, |
| 433 |
) |
| 434 |
self.update = to_raw_response_wrapper( |
| 435 |
users.update, |
| 436 |
) |
| 437 |
self.list = to_raw_response_wrapper( |
| 438 |
users.list, |
| 439 |
) |
| 440 |
self.remove = to_raw_response_wrapper( |
| 441 |
users.remove, |
| 442 |
) |
| 443 |
|
| 444 |
|
| 445 |
class AsyncUsersWithRawResponse: |
| 446 |
def __init__(self, users: AsyncUsers) -> None: |
| 447 |
self._users = users |
| 448 |
|
| 449 |
self.retrieve = async_to_raw_response_wrapper( |
| 450 |
users.retrieve, |
| 451 |
) |
| 452 |
self.update = async_to_raw_response_wrapper( |
| 453 |
users.update, |
| 454 |
) |
| 455 |
self.list = async_to_raw_response_wrapper( |
| 456 |
users.list, |
| 457 |
) |
| 458 |
self.remove = async_to_raw_response_wrapper( |
| 459 |
users.remove, |
| 460 |
) |
| 461 |
|
| 462 |
|
| 463 |
class UsersWithStreamingResponse: |
| 464 |
def __init__(self, users: Users) -> None: |
| 465 |
self._users = users |
| 466 |
|
| 467 |
self.retrieve = to_streamed_response_wrapper( |
| 468 |
users.retrieve, |
| 469 |
) |
| 470 |
self.update = to_streamed_response_wrapper( |
| 471 |
users.update, |
| 472 |
) |
| 473 |
self.list = to_streamed_response_wrapper( |
| 474 |
users.list, |
| 475 |
) |
| 476 |
self.remove = to_streamed_response_wrapper( |
| 477 |
users.remove, |
| 478 |
) |
| 479 |
|
| 480 |
|
| 481 |
class AsyncUsersWithStreamingResponse: |
| 482 |
def __init__(self, users: AsyncUsers) -> None: |
| 483 |
self._users = users |
| 484 |
|
| 485 |
self.retrieve = async_to_streamed_response_wrapper( |
| 486 |
users.retrieve, |
| 487 |
) |
| 488 |
self.update = async_to_streamed_response_wrapper( |
| 489 |
users.update, |
| 490 |
) |
| 491 |
self.list = async_to_streamed_response_wrapper( |
| 492 |
users.list, |
| 493 |
) |
| 494 |
self.remove = async_to_streamed_response_wrapper( |
| 495 |
users.remove, |
| 496 |
) |