{"id":17720337,"url":"https://github.com/HubSpot/hubspot-api-python","last_synced_at":"2025-03-14T04:30:59.155Z","repository":{"id":37758284,"uuid":"248865684","full_name":"HubSpot/hubspot-api-python","owner":"HubSpot","description":"HubSpot API Python Client Libraries for V3 version of the API","archived":false,"fork":false,"pushed_at":"2024-10-25T05:50:04.000Z","size":4435,"stargazers_count":334,"open_issues_count":31,"forks_count":106,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-10-25T08:49:20.128Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HubSpot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-20T22:41:24.000Z","updated_at":"2024-10-24T07:07:44.000Z","dependencies_parsed_at":"2023-02-02T12:31:58.886Z","dependency_job_id":"980a9deb-eb1b-4a64-b39f-245e4c83411a","html_url":"https://github.com/HubSpot/hubspot-api-python","commit_stats":{"total_commits":438,"total_committers":20,"mean_commits":21.9,"dds":0.3287671232876712,"last_synced_commit":"9411808dc634c64c6a488973af586f40d30ad0e4"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fhubspot-api-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fhubspot-api-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fhubspot-api-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fhubspot-api-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HubSpot","download_url":"https://codeload.github.com/HubSpot/hubspot-api-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221435552,"owners_count":16820683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-25T15:26:42.012Z","updated_at":"2024-10-25T15:27:18.136Z","avatar_url":"https://github.com/HubSpot.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# hubspot-api-python\n\nPython [HubSpot API](https://developers.hubspot.com/docs/api/overview) v3 SDK(Client) files and sample apps\n\nSample Applications can be found in [Sample apps](https://github.com/HubSpot/sample-apps-list)\n\n## Documentation\n\nSee the [API docs](https://developers.hubspot.com/docs/api/overview).\n\n## Installation\n\nIf you just want to use the package, run:\n\n```bash\npip install --upgrade hubspot-api-client\n```\n\n### Requirements\n\nMake sure you have [Python 3.5+](https://docs.python.org/3/) and [pip](https://pypi.org/project/pip/) installed.\n\n\n## Quickstart\n\n\n### Configuring HubSpot client\n\n```python\nfrom hubspot import HubSpot\n\napi_client = HubSpot(access_token='your_access_token')\n\n# or set your access token later\napi_client = HubSpot()\napi_client.access_token = 'your_access_token'\n```\n\nYou'll need to create a [private app](https://developers.hubspot.com/docs/api/private-apps) to get your access token or you can obtain OAuth2 access token.\n\n#### Hapikey support:\n\nPlease, note that hapikey is no longer supported after v5.1.0. You can get more info about hapikey sunset [here](https://developers.hubspot.com/changelog/upcoming-api-key-sunset). Also, plese, visit a [migration guide](https://developers.hubspot.com/docs/api/migrate-an-api-key-integration-to-a-private-app) if you need help with a migration process.\n\n### OAuth API\n\n#### Obtain OAuth2 access token:\n\n```python\nfrom hubspot.auth.oauth import ApiException\n\ntry:\n    tokens = api_client.auth.oauth.tokens_api.create(\n        grant_type=\"authorization_code\",\n        redirect_uri='http://localhost',\n        client_id='client_id',\n        client_secret='client_secret',\n        code='code'\n    )\nexcept ApiException as e:\n    print(\"Exception when calling create_token method: %s\\n\" % e)\n```\n\n### CRM API\n\n\n#### Create contact:\n\n```python\nfrom hubspot.crm.contacts import SimplePublicObjectInputForCreate\nfrom hubspot.crm.contacts.exceptions import ApiException\n\ntry:\n    simple_public_object_input_for_create = SimplePublicObjectInputForCreate(\n        properties={\"email\": \"email@example.com\"}\n    )\n    api_response = api_client.crm.contacts.basic_api.create(\n        simple_public_object_input_for_create=simple_public_object_input_for_create\n    )\nexcept ApiException as e:\n    print(\"Exception when creating contact: %s\\n\" % e)\n```\n\n#### Get contact by id:\n\n```python\nfrom hubspot.crm.contacts import ApiException\n\ntry:\n    contact_fetched = api_client.crm.contacts.basic_api.get_by_id('contact_id')\nexcept ApiException as e:\n    print(\"Exception when requesting contact by id: %s\\n\" % e)\n```\n\n#### Get custom objects page:\n\n```python\nfrom hubspot.crm.objects import ApiException\n\ntry:\n    my_custom_objects_page = api_client.crm.objects.basic_api.get_page(object_type=\"my_custom_object_type\")\nexcept ApiException as e:\n    print(\"Exception when requesting custom objects: %s\\n\" % e)\n```\n\n#### Get all:\n\n`get_all` method is available for all objects (Companies, Contacts, Deals and etc).\n\n```python\nall_contacts = api_client.crm.contacts.get_all()\n```\n\nPlease note that pagination is used under the hood to get all results.\n\n## Search:\n\n`do_search` method is available for all objects (Companies, Contacts, Deals and etc).\n\n### Example Search by date:\n```python\nimport hubspot\n\nfrom dateutil import parser\nfrom pprint import pprint\nfrom hubspot.crm.contacts import PublicObjectSearchRequest, ApiException\n\napi_client = hubspot.Client.create(access_token=\"YOUR_ACCESS_TOKEN\")\n\n# timestamp in milliseconds\ndate = str(int(parser.isoparse(\"XXXX-XX-XXTXX:XX:XX.XXXZ\").timestamp() * 1000))\npublic_object_search_request = PublicObjectSearchRequest(\n    filter_groups=[\n        {\n            \"filters\": [\n                {\n                    \"value\": date,\n                    \"propertyName\": \"lastmodifieddate\",\n                    \"operator\": \"EQ\"\n                }\n            ]\n        }\n    ], limit=10\n)\ntry:\n    api_response = api_client.crm.contacts.search_api.do_search(public_object_search_request=public_object_search_request)\n    pprint(api_response)\nexcept ApiException as e:\n    print(\"Exception when calling search_api-\u003edo_search: %s\\n\" % e)\n\n```\n\n### CMS API\n\n#### Get audit logs:\n\n```python\nfrom hubspot.cms.audit_logs import ApiException\n\ntry:\n    audit_logs_page = api_client.cms.audit_logs.default_api.get_page()\nexcept ApiException as e:\n    print(\"Exception when calling cards_api-\u003ecreate: %s\\n\" % e)\n```\n\n### Using utils\n\n#### Get OAuth url:\n\n```python\nfrom hubspot.utils.oauth import get_auth_url\n\nauth_url = get_auth_url(\n    scope=('contacts',),\n    client_id='client_id',\n    redirect_uri='http://localhost'\n)\n```\n\n#### Validate HubSpot request signature\n\n[Example](./sample-apps/webhooks-app/src/routes/webhooks.py) of usage from [Webhooks Sample App](./sample-apps/webhooks-app):\n\n```python\nimport os\n\nfrom datetime import datetime\nfrom flask import request\nfrom hubspot.utils.signature import Signature\n\nSignature.is_valid(\n    signature=request.headers[\"X-HubSpot-Signature\"],\n    client_secret=os.getenv(\"HUBSPOT_CLIENT_SECRET\"),\n    request_body=request.data.decode(\"utf-8\"),\n    http_uri=request.base_url,\n    signature_version=request.headers[\"X-HubSpot-Signature-Version\"],\n    timestamp=datetime.now().timestamp()\n)\n```\n\n### Retry middleware\n\nYou can pass an instance of [urllib3.util.retry.Retry](https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html) class to configure http client retries.\nWith internal error retry middleware:\n\n```python\nfrom hubspot import HubSpot\nfrom urllib3.util.retry import Retry\n\nretry = Retry(\n    total=3,\n    backoff_factor=0.3,\n    status_forcelist=(500, 502, 504),\n)\napi_client = HubSpot(retry=retry)\n```\nOr with rate limit retry middleware:\n\n```python\nfrom hubspot import HubSpot\nfrom urllib3.util.retry import Retry\n\nretry = Retry(\n    total=5,\n    status_forcelist=(429,),\n)\napi_client = HubSpot(retry=retry)\n```\n\n### Convert response object to dict\n\n`to_dict` method is available for most response objects\n\n```python\ncontacts = api_client.crm.contacts.basic_api.get_page()\nfor contact in contacts:\n    print(contact.to_dict())\n```\n\n## Sample Apps\n\nPlease, take a look at our [Sample apps](https://github.com/HubSpot/sample-apps-list)\n\n## Contributing\n\nInstall the package locally:\n\n```\npip install -e .\n```\n\nSet up the development virtualenv:\n\n```\nmake\n```\n\nRun tests:\n```\nmake test\n```\n\nRun [Black](https://github.com/psf/black) for code formatting:\n```\nmake fmt\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHubSpot%2Fhubspot-api-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHubSpot%2Fhubspot-api-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHubSpot%2Fhubspot-api-python/lists"}