---title: Releasing Numbersdescription: This code snippet will filter all numbers by a certain area code or sequence and then return all the numbers that match. Once you review the numbers that it prints out, you can uncomment the delete line and run it again to release the numbers all at once.slug: /guides/release-numberssidebar_position: 9x-custom: ported_from_readme: true needs_review: true---import Tabs from @theme/Tabs;import TabItem from @theme/TabItem;Overview--------At some point, you may need to release a large quantity of numbers in order to purchase new ones. This can be tedious to delete one by one, so this example shows one way that you can release numbers in bulk with ease. pythonfrom signalwire.rest import Client as signalwire_client# TODO: Update with your own credentialsproject_id = XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXaccess_token = PTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxspace_url = YOURSPACENAME.signalwire.comclient = signalwire_client( project_id, access_token, signalwire_space_url = space_url)print(Would you like to delete all numbers with a specific area code? If so, enter it now. If not, press Enter to skip.: )area_choice = input()print(Would you like to delete all numbers that contain a specific string? If so, enter it now. If not, press Enter to skip.: )contain_phrase_choice = input()phone_numbers = client.incoming_phone_numbers.list()filtered_numbers_list = []if area_choice != or contain_phrase_choice != : for numberData in phone_numbers: if numberData.phone_number.find(area_choice) != -1 and numberData.phone_number.find(contain_phrase_choice) != -1: filtered_numbers_list.append(numberData)print(Total Numbers -- + str(len(filtered_numbers_list)))for numberData in filtered_numbers_list: print(Deleting number -- + numberData.phone_number) # TODO: Uncomment the next line to activate deleting the numbers # client.phone_numbers(numberData.sid).delete() rubyrequire signalwire/sdk@client = Signalwire::REST::Client.new PROJECT_ID, AUTH_TOKEN, signalwire_space_url: example.signalwire.comsubstring = DELETEincoming_phone_numbers = @client.incoming_phone_numbers.listincoming_phone_numbers.each do |record| puts record.friendly_name if (record.friendly_name.match(/#{substring}/)) puts deleting number with sid #{record.sid} # @client.incoming_phone_numbers(record.sid).delete endend What are we going to do?------------------------Using this code snippet we will search through all of the numbers on your account and return/release those with a specific area code or sequence in their name.Python------### What do you need to run this code?For this code, the SignalWire Python SDK will need to be installed. It can be accessed here: [SignalWire Documentation](https://docs.signalwire.com/topics/laml-api/#laml-rest-api-client-libraries-and-sdks-python).### What do you need to replace in this code?project_id - Your project ID is an alphanumeric string that tells the SignalWire SDK where to find your project. You can find this in an easily copyable format by going to your SignalWire Portal and clicking the API tab on the left hand side. access_token - Your Auth Token is an alphanumeric string that helps to authenticate your HTTP requests to SignalWire. You can create this (if you haven’t already) or copy this in an easily copyable format by going to your SignalWire Portal and clicking the API tab. If you have not created an API token, press the blue new button. If you have, click show and copy the string. space_url - Your space URL is the domain of your space, i.e. example.signalwire.com. This can also be found in an easily copyable format within the API tab in your SignalWire space. You will need to replace the area code with that of the area code that you want to release from your account. ### Code Walkthrough#### Instantiate SignalWire Clientpythonfrom signalwire.rest import Client as signalwire_client# TODO: Update with your own credentialsproject_id = XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXaccess_token = PTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxspace_url = YOURSPACENAME.signalwire.comclient = signalwire_client( project_id, access_token, signalwire_space_url = space_url)#### Prompt for filtering preferencesHere we ask the user for a specific area code or sequence to look for in the numbers list. These choices will be used in a bit, to filter through all of the phone numbers we get back.pythonprint(Would you like to delete all numbers with a specific area code? If so, enter it now. If not, press Enter to skip.: )area_choice = input()print(Would you like to delete all numbers that contain a specific string? If so, enter it now. If not, press Enter to skip.: )contain_phrase_choice = input()#### Get the list of numbers and filter themWe use the List Incoming Phone Numbers API to get the list of phone numbers in our SignalWire Project, and then look for all numbers than contain either the area code or number sequence the user selected, to add them to filtered_numbers_list. Lastly, we print the total amount of numbers. pythonphone_numbers = client.incoming_phone_numbers.list()filtered_numbers_list = []if area_choice != or contain_phrase_choice != : for numberData in phone_numbers: if numberData.phone_number.find(area_choice) != -1 and numberData.phone_number.find(contain_phrase_choice) != -1: filtered_numbers_list.append(numberData)print(Total Numbers -- + str(len(filtered_numbers_list)))#### Complete DeletionLastly, we go through the filtered_numbers_list, and print a confirmation string of the numbers that will be deleted. Since this is not reversible, only after making sure the list of numbers is correct should we uncomment the last line, that actually connects to SignalWires Rest Client and makes the request to delete each number.pythonfor numberData in filtered_numbers_list: print(Deleting number -- + numberData.phone_number) # TODO: Uncomment the next line to activate deleting the numbers # client.phone_numbers(numberData.sid).delete()Ruby----### What do you need to run this code?You will need the [SignalWire Ruby SDK](https://docs.signalwire.com/topics/laml-api/#laml-rest-api-client-libraries-and-sdks-ruby)### What do you need to replace in this code?What variables change PROJECTID - Your project ID is an alphanumeric string that tells the SignalWire SDK where to find your project. You can find this in an easily copyable format by going to your SignalWire Portal and clicking the API tab on the left-hand side.TOKEN - Your Auth Token is an alphanumeric string that helps to authenticate your HTTP requests to SignalWire. You can create this (if you haven’t already) or copy this in an easily copyable format by going to your SignalWire Portal and clicking the API tab. If you have not created an API token, press the blue new button. If you have, click show and copy the string.YOURSPACENAME.signalwire.com - Your space URL is the domain of your space, i.e. example.signalwire.com. This can also be found in an easily copyable format within the API tab in your SignalWire space.substring - You will need to change the keyword in this script to whatever keyword you want the script to search your numbers for.### Code WalkthroughHere is an example of a Ruby script to be used to delete numbers that contain a specific word (delete all numbers whose names contain the word “DELETE” for example).#### Instantiate SignalWire Clientrubyrequire signalwire/sdk@client = Signalwire::REST::Client.new PROJECTID, TOKEN, signalwire_space_url: YOURSPACENAME.signalwire.com#### Get the list of numbers and select the substring filter to useWe select the substring to use when filtering through the numbers list, and use the List Incoming Phone Numbers API to get the actual list of phone numbers in our SignalWire Project.rubysubstring = DELETEincoming_phone_numbers = @client.incoming_phone_numbers.list#### Loop through the list of numbers and delete themLastly, we look through the list of numbers and only create the delete request for the ones where the substring selected in the previous step exists in the number. Since this is not reversible, only after making sure the list of numbers is correct should we uncomment line number 5, that actually connects to SignalWires Rest Client and makes the request to delete each number.rubyincoming_phone_numbers.each do |record| puts record.friendly_name if (record.friendly_name.match(/#{substring}/)) puts deleting number with sid #{record.sid} # @client.incoming_phone_numbers(record.sid).delete endendGetting Started Guide---------------------If you are looking for more information about using SignalWire, refer to our [Getting Started](/guides/signing-up-for-a-space) guide. Please feel free to reach out to us on our Community Slack or create a Support ticket if you need guidance!Sign Up Here------------If you would like to test this example out, you can create a SignalWire account and space [here](https://m.signalwire.com/signups/new?s=1).Please feel free to reach out to us on our [Community Slack](http://signalwire.community/) or create a Support ticket if you need guidance!