Affinity Python SDK¶
A modern, strongly-typed Python wrapper for the Affinity CRM API, with a scriptable CLI
(xaffinity), a local MCP server, and Claude Code plugins.
It covers companies, persons, opportunities, lists and list entries, field values, notes, reminders, interactions, meetings, transcripts, files, relationship strengths, teams, users, webhooks and more, using Affinity's V2 API wherever it can and V1 where it can't (API coverage). Use it for code, scripts and terminal work: bulk updates, exports, data pipelines, webhooks and integrations. Affinity also runs an official, hosted MCP server for working in a chat; see how the two compare.
Disclaimer: This is an unofficial community project and is not affiliated with, endorsed by, or sponsored by Affinity. “Affinity” and related marks are trademarks of their respective owners. Use of the Affinity API is subject to Affinity’s Terms of Service.
Install¶
pip install affinity-sdk
Requires Python 3.10+.
Quickstart¶
from affinity import Affinity
with Affinity(api_key="your-api-key") as client:
me = client.whoami()
print(me.user.email)
Next steps¶
- Getting started - Authentication, first request, common patterns
- Examples
- CLI
- AI Integrations - MCP Server & Claude Code plugins
- Troubleshooting
- API reference
Guides¶
- Authentication - API keys, env vars, context managers
- Configuration - Client options, timeouts, caching, policies
- Migrating to 2.0 - What changed from 1.x
- API versions and V1/V2 routing
- Pagination - Iterating large result sets
- Filtering - Filter query syntax
- Field values - Reading and updating field values
- Query command - Structured queries from the CLI
- Webhooks - Subscriptions and parsing events
- Errors & retries - Exception handling
- Rate limits - Managing API quotas
- Datetime handling - Timezone behavior
- Sync vs async - Choosing the right client