<commit_before>.. module:: twilio.rest.resources

=================
Phone Numbers
=================

With Twilio you can search and buy real phones numbers, just using the API.

For more information, see the `IncomingPhoneNumbers REST Resource <http://www.twilio.com/docs/api/rest/incoming-phone-numbers>`_ documentation.


Searching and Buying a Number
--------------------------------

Finding numbers to buy couldn't be easier. We first search for a number in area code 530. Once we find one, we'll purchase it for our account.

.. code-block:: python

    from twilio.rest import TwilioRestClient

    client = TwilioRestClient()
    numbers = client.phone_numbers.search(area_code=530)

    if len(numbers) > 0:
        numbers[0].purchase()
    else:
        print "No numbers in 530 available"

Toll Free Numbers
^^^^^^^^^^^^^^^^^^^^^^^^

By default, :meth:`search` looks for local phone numbers. Set :data:`type` to ``tollfree`` to search toll-free numbers instead.

.. code-block:: python

    numbers = client.phone_numbers.search(type="tollfree")


Numbers Containing Words
^^^^^^^^^^^^^^^^^^^^^^^^^^

Phone number search also supports looking for words inside phone numbers. The following example will find any phone number with "FOO" in it.

.. code-block:: python
<commit_msg>more idiomatic python<commit_after>.. module:: twilio.rest.resources

=================
Phone Numbers
=================

With Twilio you can search and buy real phones numbers, just using the API.

For more information, see the `IncomingPhoneNumbers REST Resource <http://www.twilio.com/docs/api/rest/incoming-phone-numbers>`_ documentation.


Searching and Buying a Number
--------------------------------

Finding numbers to buy couldn't be easier. We first search for a number in area code 530. Once we find one, we'll purchase it for our account.

.. code-block:: python

    from twilio.rest import TwilioRestClient

    client = TwilioRestClient()
    numbers = client.phone_numbers.search(area_code=530)

    if numbers:
        numbers[0].purchase()
    else:
        print "No numbers in 530 available"

Toll Free Numbers
^^^^^^^^^^^^^^^^^^^^^^^^

By default, :meth:`search` looks for local phone numbers. Set :data:`type` to ``tollfree`` to search toll-free numbers instead.

.. code-block:: python

    numbers = client.phone_numbers.search(type="tollfree")


Numbers Containing Words
^^^^^^^^^^^^^^^^^^^^^^^^^^

Phone number search also supports looking for words inside phone numbers. The following example will find any phone number with "FOO" in it.

.. code-block:: python

{'fraction_non_alphanumeric': 0.16556804963164018, 'fraction_numerical': 0.0081426909654905, 'mean_word_length': 3.6823956442831216, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5690075', 'n_tokens_mistral': 740, 'n_tokens_neox': 676, 'n_words': 269}