{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/number-lookup-api-v2/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["partial"]},"product":"Number Lookup API","type":"markdown"},"seo":{"title":"Python SDK Reference | Number Lookup API | Sinch","siteUrl":"https://developers.sinch.com","llmstxt":{"title":"Sinch Developer Documentation","description":"LLMs.txt containing a map of all the documentation files for Sinch.","sections":[{"title":"SMS API","description":"The SMS API allows you to send and receive SMS messages with a few easy steps. You can also send bulk SMS messages to multiple customers using the Sinch SMS service.","includeFiles":["docs/sms/**/*.md","docs/sms/**/*.yaml"],"excludeFiles":["docs/sms/index.md"]},{"title":"Numbers API","description":"The Numbers API enables you to search for, view, and activate numbers. It's considered a precursor to other APIs in the Sinch product family. The numbers API can be used in tandem with any of our APIs that perform messaging or calling.","includeFiles":["docs/numbers/**/*.md","docs/numbers/**/*.yaml"],"excludeFiles":["docs/numbers/index.md"]},{"title":"Conversation API","description":"Send and receive messages globally on many popular channels with ease and confidence when using Sinch's Conversation API. Conversation API is the preferred API for sending mobile messages on SMS and other social channels with Sinch. It is a simple API with unified error messages, consistent request payloads, and common webhook payloads that are channel-agnostic.","includeFiles":["docs/conversation/**/*.md","docs/conversation/**/*.yaml"],"excludeFiles":["docs/conversation/index.md"]},{"title":"Voice API","description":"The Voice API works as a big telephony switch. The Voice API handles incoming phone calls (also known as incoming call “legs”), sets up outgoing phone calls (or outgoing call “legs”), and bridges the two. The incoming call leg may come in over a data connection (from a smartphone or web application using the Sinch SDKs) or through a local phone number (from the PSTN network). Similarly, the outgoing call leg can be over data (to another smartphone or web application using the Sinch SDKs) or the PSTN network.","includeFiles":["docs/voice/**/*.md","docs/voice/**/*.yaml"],"excludeFiles":["docs/voice/index.md"]},{"title":"Verification API","description":"The Verification API is a platform for phone number verification. It consists of the API and different software development kits (the Sinch SDKs) that you integrate with your smartphone or web application and cloud based back-end services. Together they enable SMS, Flashcall, Phone Call and Data verification in your application.","includeFiles":["docs/verification/**/*.md","docs/verification/**/*.yaml"],"excludeFiles":["docs/verification/index.md"]},{"title":"Provisioning API","description":"Provisioning API allows you to programmatically set up your senders, accounts and templates on your favorite messaging platforms on the Conversation API. For now, you can create your first WhatsApp channel through Meta's Embedded sign up, you can configure your first SMS App and configure your webhooks. As development continues, we will be adding the most commonly used channels.","includeFiles":["docs/provisioning-api/**/*.md","docs/provisioning-api/**/*.json"],"excludeFiles":["docs/provisioning-api/index.md"]},{"title":"Elastic SIP Trunking API","description":"With Elastic SIP Trunking you can create and manage your SIP trunks and phone numbers programmatically.","includeFiles":["docs/est/**/*.md","docs/est/**/*.yaml"],"excludeFiles":["docs/est/index.md"]},{"title":"Fax API","description":"Send and receive HIPAA compliant faxes on our modern fax platform using our developer-friendly API.","includeFiles":["docs/fax/**/*.md","docs/fax/**/*.yaml"],"excludeFiles":["docs/fax/index.md"]},{"title":"In-app Voice and Video SDK","description":"The In-app Voice and Video SDK enables you to add voice and video calling capabilities directly into your mobile or web application using the Sinch SDKs.","includeFiles":["docs/in-app-calling/**/*.md"],"excludeFiles":["docs/in-app-calling/index.md"]}],"hide":false,"excludeFiles":[]},"description":"Learn the syntax of the Sinch Python SDK for Number Lookup API."},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"sinch-python-sdk-for-numbers","__idx":0},"children":["Sinch Python SDK for Numbers"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Python SDK allows you to quickly interact with the ","Number Lookup API"," from inside your Python applications. When using the Python SDK, the code representing requests and queries sent to and responses received from the ","Number Lookup API"," are structured similarly to those that are sent and received using the ","Number Lookup API","."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The fastest way to get started with the SDK is to check out our ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/number-lookup-api-v2/getting-started/python/lookup-number"},"children":["getting started"]}," guides. There you'll find all the instructions necessary to download, install, set up, and start using the SDK."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"syntax","__idx":1},"children":["Syntax"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide describes the syntactical structure of the Python SDK for the Number Lookup API, including any differences that may exist between the API itself and the SDK. For a full reference on Number Lookup API calls and responses, see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/number-lookup-api-v2/api-reference/number-lookup-v2"},"children":["Number Lookup API Reference"]},"."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The code sample on this page is an example of how to use the Python SDK to look up a phone number. We've also provided an example that accomplishes the same task using the REST API."]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/code-snippets/python_sdk/number-lookup/lookup-number.sample.py","language":"python","title":"snippet.py","header":{"title":"snippet.py","controls":{"copy":{}}},"lang":"python","source":"\"\"\"\nSinch Python Snippet\n\nThis snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets\n\"\"\"\n\nimport os\nfrom dotenv import load_dotenv\nfrom sinch import SinchClient\n\nload_dotenv()\n\nsinch_client = SinchClient(\n    project_id=os.environ.get(\"SINCH_PROJECT_ID\") or \"MY_PROJECT_ID\",\n    key_id=os.environ.get(\"SINCH_KEY_ID\") or \"MY_KEY_ID\",\n    key_secret=os.environ.get(\"SINCH_KEY_SECRET\") or \"MY_KEY_SECRET\",\n)\n\n# The phone number to look up in E.164 format (e.g. +1234567890)\nphone_number = \"PHONE_NUMBER\"\n\nresponse = sinch_client.number_lookup.lookup(number=phone_number)\n\nprint(f\"Number lookup result:\\n{response}\")\n"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Json","header":{"controls":{"copy":{}}},"source":"\nimport requests\n\nkey = \"YOUR_access_key\"\nsecret = \"YOUR_access_secret\"\nproject_id = \"YOUR_project_id\"\nnumber = \"YOUR_phone_number\"\nurl = \"https://lookup.api.sinch.com/v2/projects/\" + project_id + \"/lookups\"\n\ndef lookup(num):\n    payload = {\n        \"number\": num\n    }\n\n    headers = {\n        \"Content-Type\": \"application/json\"\n    }\n\n    response = requests.post(url, json=payload, headers=headers, auth=(key, secret))\n\n    data = response.json()\n    print(data)\n\nlookup(number)\n\n","lang":"Json"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This example highlights the following required to successfully make a Number Lookup API call using the Sinch Python SDK:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"#client"},"children":["Client initialization"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"#numbers-domain"},"children":["Numbers domain access"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"#endpoint-categories"},"children":["Endpoint usage"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"#request-and-query-parameters"},"children":["Field population"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"client","__idx":2},"children":["Client"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When using the Sinch Python SDK, you initialize communication with the Sinch backend by initializing the Python SDK's main client class. This client allows you to access the the functionality of the Sinch Python SDK."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"initialization","__idx":3},"children":["Initialization"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To start using the SDK, you need to initialize the main client class with your credentials from your Sinch ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://dashboard.sinch.com"},"children":["dashboard"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from sinch import SinchClient\n\nsinch_client = SinchClient(key_id=\"key_id\", key_secret=\"key_secret\", project_id=\"YOUR_project_id\")\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials, as in the following example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import os\nfrom sinch import SinchClient\n\nsinch_client = SinchClient(\n    key_id=os.getenv(\"KEY_ID\"),\n    key_secret=os.getenv(\"KEY_SECRET\"),\n    project_id=os.getenv(\"PROJECT_ID\")\n)\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"numbers-domain","__idx":4},"children":["Numbers domain"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Python SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sinch_client.number_lookup.[endpoint_category].[method]"]},". You can also create a domain-specific client from a general client. For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nfrom sinch import SinchClient\n\nsinch_client = SinchClient(key_id=\"YOUR_key_id\", key_secret=\"YOUR_key_secret\",\nproject_id=\"YOUR_project_id\")\n\nfrom sinch.domains.number_lookup import NumberLookup\n\nnumber_lookup_client = NumberLookup(sinch_client)\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"endpoint-categories","__idx":5},"children":["Endpoint categories"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In the Sinch Python SDK, Number Lookup API endpoints are accessible through the client (either a general client or a Number Lookup-specific client). The naming convention of the endpoint's representation in the SDK matches the API:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lookup"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nlookup_number = sinch_client.number_lookup.lookup(number=\"YOUR_PHONE_NUMBER\")\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"lookup-endpoint-category","__idx":6},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lookup"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lookup"]}," category of the Python SDK corresponds to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/number-lookup-api-v2/api-reference/number-lookup-v2/numberlookupv2/"},"children":["lookup"]}," endpoint. The mapping between the API operations and corresponding Python methods are described below:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/number-lookup-api-v2/api-reference/number-lookup-v2/numberlookupv2/numberlookupv2_lookup"},"children":["Look up a phone number"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lookup"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"request-and-query-parameters","__idx":7},"children":["Request and query parameters"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Requests and queries made using the Python SDK are similar to those made using the Number Lookup API. Many of the fields are named and structured similarly. For example, consider the representations of a Number Lookup API region code. One field is represented in JSON, and the other is using our Python SDK:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"mobile_country_code = \"310\"\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\"mobileCountryCode\": \"310\"\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that the fields are nearly the same. Additionally, path parameters, request body parameters, and query parameters that are used in the API are all passed as arguments to the corresponding Python method."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"field-name-differences","__idx":8},"children":["Field name differences"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When translating field names from the Number Lookup API to the Python SDK, remember that many of the API field names are in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["camelCase"]},", whereas the Python SDK field names are in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["snake_case"]},". This pattern change manages almost all field name translations between the API and the SDK."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Below is a table detailing field names present in the Number Lookup API and their modified counterparts in the Number Lookup API Python SDK:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API field name"},"children":["API field name"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK field name"},"children":["SDK field name"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["regionCode"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["region_code"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number_type"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["types"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number_types"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mobileCountryCode"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mobile_country_code"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["swapPeriod"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["swap_period"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["phoneNumber"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["phone_number"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["portingDate"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["porting_date"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"responses","__idx":9},"children":["Responses"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Response fields match the API responses. They are delivered as Python objects, with each top-level field represented as a property. Note that any nested objects normally returned by the Number Lookup API are returned as dictionaries by the Python SDK. Additionally, if there are any responses that differ significantly from the API responses, we note them in the endpoint category documentation."]}]},"headings":[{"value":"Sinch Python SDK for Numbers","id":"sinch-python-sdk-for-numbers","depth":1},{"value":"Syntax","id":"syntax","depth":2},{"value":"Client","id":"client","depth":2},{"value":"Initialization","id":"initialization","depth":3},{"value":"Numbers domain","id":"numbers-domain","depth":2},{"value":"Endpoint categories","id":"endpoint-categories","depth":2},{"value":"lookup endpoint category","id":"lookup-endpoint-category","depth":3},{"value":"Request and query parameters","id":"request-and-query-parameters","depth":2},{"value":"Field name differences","id":"field-name-differences","depth":3},{"value":"Responses","id":"responses","depth":2}],"frontmatter":{"seo":{"title":"Python SDK Reference | Number Lookup API | Sinch","description":"Learn the syntax of the Sinch Python SDK for Number Lookup API."},"product":"Number Lookup API"},"lastModified":"2026-04-08T16:46:36.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/number-lookup-api-v2/sdk/python/syntax-reference","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}