{"id":20364338,"url":"https://github.com/bandwidth/python-numbers-sdk","last_synced_at":"2025-09-02T20:40:03.870Z","repository":{"id":243943045,"uuid":"811918636","full_name":"Bandwidth/python-numbers-sdk","owner":"Bandwidth","description":"Python Numbers SDK","archived":false,"fork":false,"pushed_at":"2025-02-12T21:17:11.000Z","size":269,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":21,"default_branch":"main","last_synced_at":"2025-03-23T06:02:10.455Z","etag":null,"topics":["sdlc-enforced"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bandwidth.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-06-07T15:01:49.000Z","updated_at":"2025-02-12T21:17:13.000Z","dependencies_parsed_at":"2024-07-10T05:25:05.569Z","dependency_job_id":"c3f101aa-fe02-44a9-8466-9a3e4b669475","html_url":"https://github.com/Bandwidth/python-numbers-sdk","commit_stats":null,"previous_names":["bandwidth/python-numbers-sdk"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bandwidth%2Fpython-numbers-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bandwidth%2Fpython-numbers-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bandwidth%2Fpython-numbers-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bandwidth%2Fpython-numbers-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bandwidth","download_url":"https://codeload.github.com/Bandwidth/python-numbers-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248519311,"owners_count":21117756,"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":["sdlc-enforced"],"created_at":"2024-11-15T00:11:21.371Z","updated_at":"2025-04-12T04:41:45.455Z","avatar_url":"https://github.com/Bandwidth.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Numbers SDK\n\n## Needed tools\n\n    - Python \u003e=3.7\n    - pip\n\n## Requires\n\n    - future\n    - requests\n\n## Install\n```sh\npip install bandwidth-numbers-sdk\n```\n\n## Testing\n\nTests require the *mock* and *requests_mock* packages. You can install them\nwith\n\n```sh\npip install -r test-requirements.txt\n```\nThe tests can be run by issuing\n```sh\npytest\n```\n\n## Usage\n\n```python\nfrom bandwidth_numbers import Account, Client\n\nclient = Client(url=\"https://dashboard.bandwidth.com/api\", account_id=123456, username=\"foo\",\n    password=\"bar\")\n```\nor\n```python\nclient = Client(filename=\u003cpath to config\u003e)\n```\n\n### Config format\n```ini\n[account]\naccount_id = 123456789\nusername   = spam\npassword   = ham\n\n[rest]\nurl = https://dashboard.bandwidth.com/api\n```\n\n## Examples\n\nThere is an 'examples' folder in the source tree that shows how each of the\nAPI objects work with simple example code. To run these make a copy of\n'config.cfg.example', rename to 'config.cfg', edit it to match your IRIS\ncredentials and run the examples individually, e.g.,\n\n```console\npython available_numbers.py\n```\n\nIf an example takes command line parameters, you will get the usage info by\njust executing it.\n\n## API objects\n\n### General principles\n\nIn most cases you should use an Account object as a starting point.\n\n```python\naccount = Account(client=client)\n```\n\nAccount has related entities such as Orders, Sites, etc.\n\n```python\nsites = account.sites.list()\nfor site in sites.items:\n   pass\n```\n\n### Pagination\n\nSome resources provide paginated result sets and require the use of\npage/size parameters. In these cases a Links object will be provided for\niterating over the results.\n\n```python\nin_service_numbers = account.in_service_numbers.list({\"page\": 1, \"size\": 10})\n\ntotal = int(account.in_service_numbers.total_count)\ntotal_displayed = len(in_service_numbers.items)\npage = None\n\nwhile total_displayed \u003c= total:\n    if page is not None:\n        in_service_numbers = account.in_service_numbers.list(\n            {\"page\": page, \"size\": 10})\n    page = account.in_service_numbers.links.next\n    for phone_number in in_service_numbers.items:\n        print(phone_number)\n    total_displayed += len(in_service_numbers.items)\n```\n\n### Available numbers\n\n```python\naccount.available_numbers.list({\"areaCode\": 818})\n```\n\n### Available Npa-Nxx\n\n```python\naccount.available_npa_nxx.list({\"state\": \"NJ\"})\n```\n\n### Cities\n\n```python\nfrom bandwidth_numbers import Cities\n\ncities = Cities(client=client)\ncities.list({\"state\": \"NC\"})\n```\n\n### Covered rate centers\n\n```python\nfrom bandwidth_numbers import CoveredRateCenters\n\nrate_centers = CoveredRateCenters(client=client)\nrate_centers.list({\"page\": 1, \"size\": 10})\n```\n\n### Disconnected numbers\n\n```python\naccount.disconnected_numbers.list({\"areaCode\": 919})\n```\n\n### Disconnecting telephone numbers\n\n#### Creating disconnect orders\n\n```python\ndisconnect = account.disconnects.create({\n    \"name\": \"test disconnect order 4\",\n    \"customer_order_id\": \"Disconnect1234\",\n    \"disconnect_telephone_number_order_type\": {\n        \"telephone_number_list\": {\n            \"telephone_number\": [\"9192755378\", \"9192755703\"]\n        }\n    }\n})\n```\n\n#### Getting order data\n\n```python\ndisconnect = account.disconnects.get(\"b902dee1-0585-4258-becd-5c7e51ccf5e1\")\n```\n\n#### Adding notes\n\n```python\ndisconnect.notes.create({\"user_id\": \"spam\", \"description\": \"ham\"})\n```\n\n#### Getting all order's notes\n\n```python\nnotes = disconnect.notes.list()\n```\n\n### Dlda\n\n#### Creating orders\n\n```python\ndlda = account.dldas.create({\n    \"customer_order_id\": \"123\",\n    \"dlda_tn_groups\": {\n        \"dlda_tn_group\": [{\n            \"telephone_numbers\": {\n                \"telephone_number\": [\"4352154856\"]\n                \"account_type\": \"RESIDENTIAL\",\n                \"listing_type\": \"LISTED\",\n                \"list_address\": \"true\",\n                \"listing_name\": {\n                    \"first_name\": \"FirstName\",\n                    \"first_name2\": \"FirstName2\",\n                    \"last_name\": \"LastName\",\n                    \"designation\": \"Designation\",\n                    \"title_of_lineage\": \"TitleOfLineage\",\n                    \"title_of_address\": \"TitleOfAddress\",\n                    \"title_of_address2\": \"TitleOfAddress2\",\n                    \"title_of_lineage_name2\": \"TitleOfLineageName2\",\n                    \"title_of_address_name2\": \"TitleOfAddressName2\",\n                    \"title_of_address2_name2\": \"TitleOfAddress2Name2\",\n                    \"place_listing_as\": \"PlaceListingAs\",\n                },\n                \"address\": {\n                    \"house_prefix\": \"HousePrefix\",\n                    \"house_number\": \"915\",\n                    \"house_suffix\": \"HouseSuffix\",\n                    \"pre_directional\": \"PreDirectional\",\n                    \"street_name\": \"StreetName\",\n                    \"street_suffix\": \"StreetSuffix\",\n                    \"post_directional\": \"PostDirectional\",\n                    \"address_line2\": \"AddressLine2\",\n                    \"city\": \"City\",\n                    \"state_code\": \"StateCode\",\n                    \"zip\": \"Zip\",\n                    \"plus_four\": \"PlusFour\",\n                    \"country\": \"Country\",\n                    \"address_type\": \"AddressType\"\n                }\n            }\n        }]\n    }\n})\n```\n\n#### Getting order data\n\n```python\ndlda = account.dldas.get(\"7802373f-4f52-4387-bdd1-c5b74833d6e2\")\n```\n\n#### Retrieving dlda history\n\n```python\ndlda.history.list()\n```\n\n#### Getting a list of dldas\n\n```python\naccount.dldas.list({\"telephoneNumber\": \"9195551212\"})\n```\n\n### Import TN Checker\n```python\n# returns an array of portable TN's\nresult = account.import_tn_checker(numbers=[\"3032281000\", \"9195551234\"])\nprint(result)    # ['3032281000', '9195551234']\n```\n\n### In-service numbers\n\n```python\naccount.in_service_numbers.list({\"areaCode\": \"919\"})\n```\n\n### Lidb\n\n#### Creating orders\n\n```python\nlidb = account.lidbs.create({\n    \"lidb_tn_groups\": {\n        \"lidb_tn_group\": [{\n            \"telephone_numbers\": {\n                \"telephone_number\": [\"4352154856\"]\n            },\n            \"subscriber_information\": \"Steve\",\n            \"use_type\": \"RESIDENTIAL\",\n            \"visibility\": \"PUBLIC\"\n        },\n        {\n            \"telephone_numbers\": {\n                \"telephone_number\": [\"4352154855\"]\n            },\n            \"subscriber_information\": \"Steve\",\n            \"use_type\": \"RESIDENTIAL\",\n            \"visibility\": \"PUBLIC\"\n        }]\n    }\n})\n\n```\n\n#### Getting order data\n\n```python\nlidb = account.lidbs.get(\"7802373f-4f52-4387-bdd1-c5b74833d6e2\")\n```\n\n#### Getting a list of lidbs\n\n```python\nlidbs = account.lidbs.list({\"last_modified_after\": \"mm-dd-yy\",\n    \"telephone_number\": \"888\"})\n```\n\n### LNP Checker\n\n```python\naccount.lnpChecker([\"4109255199\", \"9196190594\"], \"true\")\n```\n\n### Phone numbers orders\n\n#### Creating orders\n\n```python\norder = account.orders.create({\n    \"name\": \"Available Telephone Number order\",\n    \"site_id\": \"2297\",\n    \"customer_order_id\": \"123456789\",\n    \"existing_telephone_number_order_type\": {\n        \"telephone_number_list\": {\n            \"telephone_number\": [\"9193752369\", \"9193752720\", \"9193752648\"]\n        }\n    }\n})\n```\n\n#### Getting order data\n\n```python\nresponse = account.orders.get(\"f30a31a1-1de4-4939-b094-4521bbe5c8df\")\norder = response.order\n```\n\n#### Getting a list of orders\n\n```python\norders = account.orders.list()\n```\n\n#### Adding notes\n\n```python\norder.notes.create({\"user_id\": \"spam\", \"description\": \"Test Note\"})\n```\n\n#### Getting order's telephone numbers\n\n```python\norder.tns.list()\n```\n\n### Port-ins\n\n#### Creating orders\n\n```python\nportin = account.portins.create({\n    \"billing_telephone_number\": \"6882015002\",\n    \"subscriber\": {\n        \"subscriber_type\": \"BUSINESS\",\n        \"business_name\": \"Acme Corporation\",\n        \"service_address\": {\n            \"house_number\": \"1623\",\n            \"street_name\": \"Brockton Ave\",\n            \"city\": \"Los Angeles\",\n            \"state_code\": \"CA\",\n            \"zip\": \"90025\",\n            \"country\": \"USA\"\n        }\n    },\n    \"loa_authorizing_person\": \"John Doe\",\n    \"list_of_phone_numbers\": {\n        \"phone_number\": [\"9882015025\", \"9882015026\"]\n    },\n    \"site_id\": \"365\",\n    \"triggered\": \"false\"\n})\n```\n\n#### Getting order data\n\n```python\nportin = account.portinsget(\"d28b36f7-fa96-49eb-9556-a40fca49f7c6\")\n```\n\n#### Getting a list of orders\n\n```python\nportins = account.portins.list({\"pon\": \"a pon\"})\n```\n\n#### Port-in instance methods and properties\n\n```python\nportin.save()\nportin.delete()\nportin.activation_status\n\nstatus = portin.activation_status\nstatus.auto_activation_date = \"2014-08-30T18:30:00+03:00\"\nstatus.save()\n\nportin.history\nportin.totals\nportin.notes\n```\n\n#### Port-in file management\n\n```python\nportin.loas.list({\"metadata\": \"true\"})\nfname = portin.loas.create(\"loa.pdf\", {'content-type': 'application/pdf'})\nportin.loas.update(fname, \"loa.pdf\", {'content-type':'application/pdf'})\nportin.loas.delete(fname)\nportin.loas.metadata.get(fname)\nportin.loas.metadata.document_name = \"text.txt\"\nportin.loas.metadata.document_type = \"invoice\"\nportin.loas.metadata.save()\nportin.loas.metadata.delete()\n```\n\n### Rate Centers\n\n```python\nfrom bandwidth_numbers import RateCenters\nrc = RateCenters(client=client)\ncenters = rc.list({\"state\": \"CA\", \"available\": \"true\"})\n```\n\n### SIP Peers\n\n#### Creating a SIP peer\n\n```python\nsip_peer = account.sites.list().items[0].sip_peers.create({\n        \"peer_name\": name,\n        \"is_default_peer\": \"true\",\n        \"short_messaging_protocol\": \"SMPP\",\n        \"voice_hosts\": {\n            \"host\": [{\n                \"host_name\": \"92.168.181.95\"\n            }]\n        },\n        \"sms_hosts\": {\n            \"host\": [{\n                \"host_name\": \"92.168.181.95\"\n            }]\n        },\n        \"termination_hosts\": {\n            \"termination_host\": [{\n                \"host_name\": \"92.168.181.95\",\n                \"port\": \"0\",\n                \"customer_traffic_allowed\": \"DOMESTIC\",\n                \"data_allowed\": \"true\"\n            }]\n        }\n    })\n```\n\n#### Getting a peer\n\n```python\nsip_peer = account.sites.list().items[0].sip_peers.get(\"500651\")\n```\n\n#### Getting a list of SIP peers\n\n```python\nsip_peers = account.sites.list().items[0].sip_peers.list()\n```\n\n#### Deleting SIP peers\n\n```python\nsip_peer.delete()\n```\n\n#### Moving telephone numbers\n\n```python\nsip_peer.movetns.add(\"9192000046\")\nsip_peer.movetns()\n```\n\n#### Getting peer telephone numbers\n\n```python\ntns = sip_peer.tns.list()\n```\n\n#### Getting a single phone number\n\n```python\ntn = sip_peer.tns.get(\"8183386251\")\n```\n\n#### Getting total number of numbers for a SIP peer\n\n```python\ncount = sip_peer.totaltns.get()\n```\n\n#### Setting telephone number options\n\n```python\ntn = sip_peer.tns.get(\"8183386251\")\ntn.rpid_format = \"e164\"\ntn.save()\n```\n\n### Sites\n\n#### Creating a site\n\n```python\nsite = acc.sites.create({\n    \"name\": \"test123456\",\n    \"address\": {\n        \"city\": \"Raleigh\",\n        \"address_type\": \"Service\",\n        \"house_number\": \"1\",\n        \"street_name\": \"Avenue\",\n        \"state_code\": \"NC\",\n        \"zip\": \"27606\"\n    }\n})\n```\n\n#### Updating a site\n\n```python\nsite.name = \"New Name\"\nsite.save()\n```\n\n#### Deleting a site\n\n```python\nsite.delete()\n```\n\n#### Getting a list of sites\n\n```python\nsites = account.sites.list()\n```\n\n#### Getting a list of site orders\n\n```python\nsite.orders.list({\"status\": \"disabled\"})\n```\n\n#### Getting the total number of telephone numbers for a site\n\n```python\nsite.totaltns.get()\n```\n\n#### Getting a list of site's port-in orders\n\n```python\nsite.portins.list({\"status\": \"disabled\"})\n```\n\n### Subscriptions\n\n#### Creating subscriptions\n\n```python\nsubscription = account.subscriptions.create({\n    \"order_type\": \"portins\",\n    \"order_id\": \"98939562-90b0-40e9-8335-5526432d9741\",\n    \"email_subscription\": {\n        \"email\": \"test@test.com\",\n        \"digest_requested\": \"DAILY\"\n    }\n})\n```\n\n#### Getting subscription information\n\n```python\nsubscription = account.subscriptions.get(id)\n```\n\n#### Getting a list of subscriptions\n\n```python\naccount.subscriptions.list({\"orderType\": \"portins\"})\n```\n\n#### Updating a subscription\n\n```python\nsubscription.order_type = \"portins\"\nsubscription.save()\n```\n\n#### Deleting a subscription\n\n```python\nsubscription.delete()\n```\n\n### TNs\n\n#### Getting a phone number\n\n```python\nfrom bandwidth_numbers import Tns\n\ntns = Tns(client=client)\ntn = tns.get(id)\n```\n\n#### Getting a list of TNs\n\n```python\ntns.list({\"page\": 1, \"size\": 10 })\n```\n\n#### Telephone number instance methods and properties\n\n```python\ntn = tns.get(\"7576768750\")\nsite = tn.site.get()\nsip_peer = tn.sip_peer.get()\ntnreservation = tn.tnreservation\ntn.tndetails.get()\nrc = tn.tn_rate_center.get()\nlata = tn.tn_lata.get()\nlca = tn.lca.get()\nhistory = tn.history.list()\n```\n\n### Reserving phone numbers\n\n#### Create a reservation\n\n```python\naccount.tnreservation.reserved_tn = \"2512027430\"\naccount.tnreservation.save()\n```\n\n#### Getting reservation info\n\n```python\nreservation = account.tnreservation.get(\"0099ff73-da96-4303-8a0a-00ff316c07aa\")\n```\n\n#### Deleting a reservation\n\n```python\nreservation.delete()\n```\n\n### Get TN Option Orders\n```python\norders = account.tn_option_orders.list()\nprint(orders.total_count)\nprint(orders.tn_option_order_summary.items[0].account_id)\n```\n\n### Get TN Option Order\n```python\norder = account.tn_option_orders.get(\"order_id\")\nprint(order.order_create_date)\n```\n\n### Get TN Option Order (error)\n```python\norder = account.tn_option_orders.get(\"order_id_with_error\")\nprint(order.error_list.error.items[0].description)\n```\n\n### Create PortOut Passcode\n```python\norder = account.tn_option_orders.create({\n    \"customer_order_id\": \"custom order\",\n    \"tn_option_groups\": {\n        \"tn_option_group\": [\n            {\n                \"port_out_passcode\": \"12abd38\",\n                \"telephone_numbers\": {\n                    \"telephone_number\": [\n                        \"2018551020\"\n                    ]\n                }\n            }\n        ]\n    }\n})\n\nprint(order.order_create_date)\n```\n\n### Create Call Forward Number\n```python\norder = account.tn_option_orders.create({\n    \"customer_order_id\": \"custom order\",\n    \"tn_option_groups\": {\n        \"tn_option_group\": [\n            {\n                \"call_forward\": \"2018551022\",\n                \"telephone_numbers\": {\n                    \"telephone_number\": [\n                        \"2018551020\"\n                    ]\n                }\n            }\n        ]\n    }\n})\n\nprint(order.order_create_date)\n```\n\n### Enable SMS\n```python\norder = account.tn_option_orders.create({\n    \"customer_order_id\": \"custom order\",\n    \"tn_option_groups\": {\n        \"tn_option_group\": [\n            {\n                \"sms\": \"on\",\n                \"telephone_numbers\": {\n                    \"telephone_number\": [\n                        \"2018551020\"\n                    ]\n                }\n            }\n        ]\n    }\n})\n\nprint(order.order_create_date)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbandwidth%2Fpython-numbers-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbandwidth%2Fpython-numbers-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbandwidth%2Fpython-numbers-sdk/lists"}