Models¶
Affinity data models.
All Pydantic models are available from this module.
Tip
ID types and enums live in affinity.types.
AffinityList
¶
Bases: AffinityModel
A list (spreadsheet) in Affinity.
Named AffinityList to avoid collision with Python's list type.
Source code in affinity/models/entities.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
AffinityModel
¶
Bases: BaseModel
Base model with common configuration.
Source code in affinity/models/entities.py
46 47 48 49 50 51 52 53 54 | |
AsyncPageIterator
¶
Bases: Generic[T]
Asynchronous iterator that automatically fetches all pages.
Usage
async for item in client.companies.all(): print(item.name)
Source code in affinity/models/pagination.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
all(*, limit: int | None = _DEFAULT_LIMIT) -> list[T]
async
¶
Fetch all items across all pages into a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Maximum items to fetch. Default 100,000. Set to None for unlimited. |
_DEFAULT_LIMIT
|
Returns:
| Type | Description |
|---|---|
list[T]
|
List of all items. |
Raises:
| Type | Description |
|---|---|
TooManyResultsError
|
If results exceed limit. |
Note
The check occurs after extending results, so the final list may exceed limit by up to one page before the error is raised.
Example
Default - safe for most use cases¶
persons = [p async for p in client.persons.all()] # Using async iterator
Or use .all() method with limit check¶
it = AsyncPageIterator(fetch_page) persons = await it.all() # Returns list, raises if > 100k
Explicit unlimited for large exports¶
all_persons = await it.all(limit=None)
Custom limit¶
persons = await it.all(limit=500_000)
Source code in affinity/models/pagination.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
pages(*, on_progress: Callable[[PaginationProgress], None] | None = None) -> AsyncIterator[PaginatedResponse[T]]
async
¶
Iterate through pages (not individual items).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_progress
|
Callable[[PaginationProgress], None] | None
|
Optional callback fired after fetching each page. Receives PaginationProgress with page_number, items_in_page, items_so_far, and has_next. Callbacks should be lightweight; heavy processing should happen outside the callback to avoid blocking iteration. |
None
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[PaginatedResponse[T]]
|
PaginatedResponse objects for each page. |
Example
def report(p: PaginationProgress): print(f"Page {p.page_number}: {p.items_so_far} items so far")
async for page in client.persons.all().pages(on_progress=report): process(page.data)
Source code in affinity/models/pagination.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
BatchOperationResponse
¶
Bases: AffinityModel
Response from batch field operations.
Source code in affinity/models/pagination.py
473 474 475 476 477 478 479 480 481 482 483 484 | |
BatchOperationResult
¶
Bases: AffinityModel
Result of a single operation in a batch.
Source code in affinity/models/pagination.py
465 466 467 468 469 470 | |
Company
¶
Bases: AffinityModel
Full company representation.
Note: Called Organization in V1 API.
Source code in affinity/models/entities.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
CompanyCreate
¶
Bases: AffinityModel
Data for creating a new company (V1 API).
Source code in affinity/models/entities.py
335 336 337 338 339 340 | |
CompanyUpdate
¶
Bases: AffinityModel
Data for updating a company (V1 API).
Source code in affinity/models/entities.py
343 344 345 346 347 348 | |
DropdownOption
¶
Bases: AffinityModel
A selectable option in a dropdown field.
Source code in affinity/models/entities.py
149 150 151 152 153 154 155 | |
EntityFile
¶
Bases: AffinityModel
A file attached to an entity.
Source code in affinity/models/secondary.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
FieldCreate
¶
Bases: AffinityModel
Data for creating a new field (V1 API).
Source code in affinity/models/entities.py
702 703 704 705 706 707 708 709 710 711 712 713 | |
FieldMetadata
¶
Bases: AffinityModel
Metadata about a field (column) in Affinity.
Includes both V1 numeric IDs and V2 string IDs for enriched fields.
Source code in affinity/models/entities.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
FieldValue
¶
Bases: AffinityModel
A single field value (cell data).
The value can be various types depending on the field's value_type.
Source code in affinity/models/entities.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | |
FieldValueChange
¶
Bases: AffinityModel
Historical change to a field value.
Source code in affinity/models/entities.py
761 762 763 764 765 766 767 768 769 770 771 | |
FieldValueCreate
¶
Bases: AffinityModel
Data for creating a field value (V1 API).
Source code in affinity/models/entities.py
741 742 743 744 745 746 747 | |
Grant
¶
Bases: AffinityModel
API key grant information.
Source code in affinity/models/secondary.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
scope: str | None
property
¶
Backwards-compatible convenience for older response shapes.
Returns the first scope string when present, otherwise None.
Interaction
¶
Bases: AffinityModel
An interaction (email, meeting, call, or chat message).
Different interaction types have different fields available.
Source code in affinity/models/secondary.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
InteractionCreate
¶
Bases: AffinityModel
Data for creating an interaction (V1 API).
Source code in affinity/models/secondary.py
157 158 159 160 161 162 163 164 | |
InteractionUpdate
¶
Bases: AffinityModel
Data for updating an interaction (V1 API).
Source code in affinity/models/secondary.py
167 168 169 170 171 172 173 | |
ListCreate
¶
Bases: AffinityModel
Data for creating a new list (V1 API).
Source code in affinity/models/entities.py
491 492 493 494 495 496 497 498 | |
ListEntry
¶
Bases: AffinityModel
A row in a list, linking an entity to a list.
Contains the entity data and list-specific field values.
Source code in affinity/models/entities.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
ListEntryCreate
¶
Bases: AffinityModel
Data for adding an entity to a list (V1 API).
Source code in affinity/models/entities.py
612 613 614 615 616 | |
ListEntryWithEntity
¶
Bases: AffinityModel
List entry with full entity data included (V2 response format).
Source code in affinity/models/entities.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
ListPermission
¶
Bases: AffinityModel
Additional permission on a list.
Source code in affinity/models/entities.py
430 431 432 433 434 | |
ListSummary
¶
Bases: AffinityModel
Minimal list reference used by relationship endpoints.
Source code in affinity/models/entities.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
Note
¶
Bases: AffinityModel
A note attached to one or more entities.
Notes can be plain text, HTML, or AI-generated meeting summaries.
Source code in affinity/models/secondary.py
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 67 68 69 70 71 72 | |
NoteCreate
¶
Bases: AffinityModel
Data for creating a new note (V1 API).
Source code in affinity/models/secondary.py
75 76 77 78 79 80 81 82 83 84 85 | |
NoteUpdate
¶
Bases: AffinityModel
Data for updating a note (V1 API).
Source code in affinity/models/secondary.py
88 89 90 91 | |
Opportunity
¶
Bases: AffinityModel
Deal/opportunity in a pipeline.
Note
The V2 API returns empty person_ids and company_ids arrays even
when associations exist. Use client.opportunities.get_associated_person_ids()
or client.opportunities.get_details() to retrieve association data.
See the opportunity-associations guide for details.
Source code in affinity/models/entities.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
OpportunityCreate
¶
Bases: AffinityModel
Data for creating a new opportunity (V1 API).
Source code in affinity/models/entities.py
396 397 398 399 400 401 402 | |
OpportunitySummary
¶
Bases: AffinityModel
Minimal opportunity data returned in nested contexts.
Source code in affinity/models/entities.py
418 419 420 421 422 | |
OpportunityUpdate
¶
Bases: AffinityModel
Data for updating an opportunity (V1 API).
Source code in affinity/models/entities.py
405 406 407 408 409 410 | |
PageIterator
¶
Bases: Generic[T]
Synchronous iterator that automatically fetches all pages.
Usage
for item in client.companies.all(): print(item.name)
Source code in affinity/models/pagination.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
all(*, limit: int | None = _DEFAULT_LIMIT) -> list[T]
¶
Fetch all items across all pages into a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Maximum items to fetch. Default 100,000. Set to None for unlimited. |
_DEFAULT_LIMIT
|
Returns:
| Type | Description |
|---|---|
list[T]
|
List of all items. |
Raises:
| Type | Description |
|---|---|
TooManyResultsError
|
If results exceed limit. |
Note
The check occurs after extending results, so the final list may exceed limit by up to one page before the error is raised.
Example
Default - safe for most use cases¶
persons = list(client.persons.all()) # Using iterator
Or use .all() method with limit check¶
it = PageIterator(fetch_page) persons = it.all() # Returns list, raises if > 100k
Explicit unlimited for large exports¶
all_persons = it.all(limit=None)
Custom limit¶
persons = it.all(limit=500_000)
Source code in affinity/models/pagination.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
pages(*, on_progress: Callable[[PaginationProgress], None] | None = None) -> Iterator[PaginatedResponse[T]]
¶
Iterate through pages (not individual items).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_progress
|
Callable[[PaginationProgress], None] | None
|
Optional callback fired after fetching each page. Receives PaginationProgress with page_number, items_in_page, items_so_far, and has_next. Callbacks should be lightweight; heavy processing should happen outside the callback to avoid blocking iteration. |
None
|
Yields:
| Type | Description |
|---|---|
PaginatedResponse[T]
|
PaginatedResponse objects for each page. |
Example
def report(p: PaginationProgress): print(f"Page {p.page_number}: {p.items_so_far} items so far")
for page in client.persons.all().pages(on_progress=report): process(page.data)
Source code in affinity/models/pagination.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
PaginatedResponse
¶
Bases: AffinityModel, Generic[T]
A paginated response from the API.
Provides access to the current page of results and pagination info.
Source code in affinity/models/pagination.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
has_next: bool
property
¶
Whether there are more pages.
next_cursor: str | None
property
¶
Cursor for the next page, if any.
__len__() -> int
¶
Number of items in current page.
Source code in affinity/models/pagination.py
90 91 92 | |
PaginationInfo
¶
Bases: AffinityModel
V2 pagination info returned in responses.
Source code in affinity/models/pagination.py
62 63 64 65 66 | |
PaginationProgress
dataclass
¶
Progress information for pagination callbacks.
Source code in affinity/models/pagination.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
Person
¶
Bases: AffinityModel
Full person representation.
Note: Companies are called Organizations in V1 API.
Source code in affinity/models/entities.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
full_name: str
property
¶
Get the person's full name.
PersonCreate
¶
Bases: AffinityModel
Data for creating a new person (V1 API).
Source code in affinity/models/entities.py
255 256 257 258 259 260 261 | |
PersonUpdate
¶
Bases: AffinityModel
Data for updating a person (V1 API).
Source code in affinity/models/entities.py
264 265 266 267 268 269 270 | |
RateLimitBucket
¶
Bases: AffinityModel
A single rate limit bucket (quota window).
Source code in affinity/models/rate_limit_snapshot.py
20 21 22 23 24 25 26 | |
RateLimitInfo
¶
Bases: AffinityModel
Rate limit information for an API key.
Source code in affinity/models/secondary.py
372 373 374 375 376 377 378 | |
RateLimitSnapshot
¶
Bases: AffinityModel
A best-effort snapshot of rate limit state.
Notes:
- source="headers" means the snapshot is derived from tracked HTTP response headers.
- source="endpoint" means the snapshot is derived from a dedicated endpoint response payload.
- source="unknown" means no reliable rate limit information has been observed yet.
Source code in affinity/models/rate_limit_snapshot.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
RateLimits
¶
Bases: AffinityModel
Current rate limit status.
Source code in affinity/models/secondary.py
381 382 383 384 385 | |
RelationshipStrength
¶
Bases: AffinityModel
Relationship strength between internal and external persons.
Source code in affinity/models/secondary.py
298 299 300 301 302 303 | |
Reminder
¶
Bases: AffinityModel
A reminder attached to an entity.
Source code in affinity/models/secondary.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
ReminderCreate
¶
Bases: AffinityModel
Data for creating a reminder (V1 API).
Source code in affinity/models/secondary.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
ReminderUpdate
¶
Bases: AffinityModel
Data for updating a reminder (V1 API).
Source code in affinity/models/secondary.py
225 226 227 228 229 230 231 232 233 234 | |
SavedView
¶
Bases: AffinityModel
A saved view configuration for a list.
Source code in affinity/models/entities.py
624 625 626 627 628 629 630 631 632 633 634 635 636 | |
Tenant
¶
Bases: AffinityModel
Affinity tenant (organization/team) information.
Source code in affinity/models/secondary.py
311 312 313 314 315 316 | |
WebhookCreate
¶
Bases: AffinityModel
Data for creating a webhook subscription (V1 API).
Source code in affinity/models/secondary.py
252 253 254 255 256 | |
WebhookSubscription
¶
Bases: AffinityModel
A webhook subscription for real-time events.
Source code in affinity/models/secondary.py
242 243 244 245 246 247 248 249 | |
WebhookUpdate
¶
Bases: AffinityModel
Data for updating a webhook subscription (V1 API).
Source code in affinity/models/secondary.py
259 260 261 262 263 264 | |
WhoAmI
¶
Bases: AffinityModel
Response from whoami endpoint.
Source code in affinity/models/secondary.py
359 360 361 362 363 364 | |