# Look up a number with Python The Number Lookup API lets you look up a phone number to verify it's in service and to check information about the number such as the carrier. In this tutorial you will learn how to look up numbers in bulk using Python. In this guide you will learn: 1. How to [set up](#set-up-your-python-application-and-install-dependencies) your Python application. 2. [Bulk look up](#bulk-look-up-your-phone-numbers) your phone numbers. ## What you need to know before you start Before you can get started, you need the following already set up: * Set all Number Lookup API [configuration settings](/docs/number-lookup-api-v2/getting-started). * [Python](https://www.python.org/) and a familiarity with how to create a new file. * [PIP (package installer for Python)](https://pypi.org/project/pip/) and a familiarity with how to install Python modules. ## Set up your Python application and install dependencies We'll be using the `requests` module to make HTTP requests. If it's not already installed globally, open a command prompt and use the following command to install the `requests` module: ```shell pip install requests ``` Create a new file named `app.py` and paste the provided "app.py" code found on this page into the file. Note: This tutorial uses basic authentication for testing purposes. We recommend using OAuth for authentication in a production environment. You can follow the steps in this guide, but use the code samples from [here](/docs/number-lookup-api-v2/api-reference/authentication/oauth) to use OAuth authentication instead. app.py # Use this code to look up numbers in bulk. import requests import json key = "YOUR_access_key" secret = "YOUR_access_secret" project_id = "YOUR_project_id" file_path = "phone_numbers.txt" def lookup(num): url = "https://lookup.api.sinch.com/v2/projects/" + project_id + "/lookups" payload = { "number": num } headers = { "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers, auth=(key, secret)) data = response.json() text = json.dumps(data) write_file(num + '\n' + text) def write_file(text): try: with open("results.txt", 'a') as file: file.write(text + '\n') except Exception as e: print(f"Error: {e}") def read_file(path): phone_numbers = [] file = open(path, 'r') content = file.readlines() for line in content: phone_numbers.append(line.strip()) return phone_numbers def bulk_lookup(array_of_numbers): for number in array_of_numbers: lookup(number) bulk_lookup(read_file(file_path)) This code contains the logic to read in a list of phone numbers in a text file, look up those numbers, and then write the results of the number lookup calls to a new text file named `results.txt` in the project folder. To make this tutorial work, you should have a text file of phone numbers formatted to E.164 standard, with each number on a new line. For example, the text file should look like this: ```text +12345678900 +13334445656 +15556789999 ``` ## Fill in your parameters Before you can run the code, you need to update some values so you can connect to your Sinch account. Update the following parameters with your own values: Assign your values to the following parameters: | Parameter | Your value | | --- | --- | | `key` | The key found on your Sinch [Build dashboard](https://dashboard.sinch.com/settings/access-keys). | | `secret` | The secret found on your Sinch [Build dashboard](https://dashboard.sinch.com/settings/access-keys). | | `project_id` | Your project ID found on your Sinch [Build dashboard](https://dashboard.sinch.com/settings/access-keys). | | `file_path` | This is the file path to the text file containing the phone numbers you want to look up. | Save the file. ## Bulk look up your phone numbers Now you can execute the code and look up your phone numbers. Run the following command: ```shell python app.py ``` The application should create a text file named `results.txt` in your project folder, containing the information responses for each of the phone numbers in your original list of numbers. Troubleshooting tip If after running your app you receive a 5000 error response, you may have forgotten to save your file after adding your authentication values. This is an easy mistake to make! Try saving the file and running the app again. ## Additional resources - [API specification](/docs/number-lookup-api-v2/api-reference/)