Package: telnyx
Telnyx Python LibraryThe Telnyx Python library provides convenient access to the Telnyx API from
applications written in the Python language. It includes a pre-defined set of
classes for API resources that initialize themselves dynamically from API
responses which makes it compatible with a wide range of versions of the Telnyx
API.DocumentationSee theAPI Referenceand theSetup Guides.InstallationYou don't need this source code unless you want to modify the package. If you just
want to use the package, just run:pip install --upgrade telnyxInstall from source with:python setup.py installNon x86/x86_64 ProcessorsThetelnyxpackage is distributed as a wheel (pre-compiled package) for easy
installation. The wheel is built only for x86/x86_64 processors. When
installing the package on a different architecture, like ARM, thepipinstaller will fall back to installing from source. As a result, you will
need to ensure you have the additional dependencies installed. This will
affect you if you're using a Raspberry Pi, for example.For ARM specifically, as an alternative to a source install, you could look
into usinghttps://www.piwheels.org/for ARM compiled wheels.RequirementsPython 3.8+ (PyPy supported)Additional Requirements for Source Installbuild-essentials (gcc, make)python-devlibffi-devThese packages are listed as they are named on Ubuntu.UsageThe library needs to be configured with your account's API Key which is
available in yourTelnyx Dashboard. Settelnyx.api_keyto its
value:importtelnyxtelnyx.api_key="KEY01234_yoursecretkey"# Retrieve single Messaging Profiletelnyx.MessagingProfile.retrieve("123")# List Messaging Profilesprofiles=telnyx.MessagingProfile.list()# Retrieve next page of list resultsprofiles.next_page()# Loop over all page resultsforpageinprofiles.auto_paging_iter():print(page)You can read more about our API Keyshere.Per-Request ConfigurationFor apps that need to use multiple keys during the lifetime of a process,
it's also possible to set a per-request key and/or account:importtelnyx# list messaging profilestelnyx.MessagingProfile.list(api_key="super-secret...",)# retrieve single messaging profiletelnyx.MessagingProfile.retrieve("123",api_key="other-secret...",)Configuring an HTTP ClientThe library can be configured to useurlfetch,requests,pycurl, orurllib2withtelnyx.default_http_client:client=telnyx.http_client.UrlFetchClient()client=telnyx.http_client.RequestsClient()client=telnyx.http_client.PycurlClient()client=telnyx.http_client.Urllib2Client()telnyx.default_http_client=clientWithout a configured client, by default the library will attempt to load
libraries in the order above (i.e.urlfetchis preferred withurllib2used
as a last resort). We usually recommend that people userequests.Configuring a ProxyA proxy can be configured withtelnyx.proxy:telnyx.proxy="https://user:pass@example.com:1234"Configuring Automatic RetriesNumber of automatic retries on requests that fail due to an intermittent
network problem can be configured:telnyx.max_network_retries=2Reserved word keyword argumentsThe Telnyx API includesfromas an attribute that can be set on messages.fromis also a reserved word in Python. If you would like to use keyword
arguments where an argument is a reserved word you can add the suffix_e.g.telnyx.Message.create(
    to="+18665550001",
    from_="+18445550001",
    text="Foo"
)The argument will be automatically rewritten tofromin the keyword arguments dict.Pro Tip: You can alternatively unpack a dictionary like so:message={"from":"+18445550001","to":"+18665550001","text":"Foo",}telnyx.Message.create(**message)LoggingThe library can be configured to emit logging that will give you better insight
into what it's doing. Theinfologging level is usually most appropriate for
production use, butdebugis also available for more verbosity.There are a few options for enabling it:Set the environment variableTELNYX_LOGto the valuedebugorinfo$ export TELNYX_LOG=debugSettelnyx.log:importtelnyxtelnyx.log='debug'Enable it through Python's logging module:importlogginglogging.basicConfig()logging.getLogger('telnyx').setLevel(logging.DEBUG)Writing a PluginIf you're writing a plugin that uses the library, we'd appreciate it if you
identified usingtelnyx.set_app_info():telnyx.set_app_info("MyAwesomePlugin",version="1.2.34",url="https://myawesomeplugin.info")This information is passed along when the library makes calls to the Telnyx
API.DevelopmentThe test suite depends ontelnyx-mock, so make sure to fetch and run it from a
background terminal (telnyx-mock's READMEalso contains
instructions for installing via Homebrew and other methods):go get -u github.com/team-telnyx/telnyx-mock
telnyx-mockInstallpipenv, then install all dependencies for the project:pipenv install --devRun all tests on all supported Python versions:make testRun all tests for a specific Python version (modify-eaccording to your Python target):pipenv run tox -e py38Run all tests in a single file:pipenv run tox -e py38 -- tests/api_resources/abstract/test_updateable_api_resource.pyRun a single test suite:pipenv run tox -e py38 -- tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResourceRun a single test:pipenv run tox -e py38 -- tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource::test_saveRun the linter with:make lintThe library usesBlackfor code formatting. Code must be formatted
with Black before PRs are submitted, otherwise CI will fail. Run the formatter
with:make fmtAdding a new endpointDefine a class for the object that the endpoint interacts with undertelnyx/api_resources/. The path name singularized should typically match
the record type of the object returned e.g./v2/available_phone_numbersreturns a list of objects with the record_typeavailable_phone_number.
Inherit from the classes that define the behavior available on the endpoint,one or more ofCreateableAPIResource,DeletableAPIResource,ListableAPIResource,UpdateableAPIResource.Import your class intelnyx/api_resources/__init__.py.Add your new class to theOBJECT_CLASSESblock intelnyx/util.py.Add tests for your new class undertests/api_resources/.ReleasingUpdate version insetup.py(in thesetup()call, theversionkwarg)telnyx/__init__.py(the__version__string)Create new branch, add changes, commit, and pushEnsure commit passes tests inTravisTag that commit withgit tag -a v{VERSION} -m "Release v{VERSION}", and push the taggit push --follow-tagsEnsure checked out copy is entirely clean (best to create a new environment...)make distsIf you haven't done it before, download the upload API keys from LastPass (search for "pypi") and put the contents between "PYPIRC FILE" tags into~/.pypirc-telnyx.make testupload, check that it looks OK on PyPI and that it's installable viapip.make liveupload, repeat checks for live version.Ta-da.AcknowledgmentsThe contributors and maintainers of Telnyx Python would like to extend their
deep gratitude to the authors ofStripe Python, upon which
this project is based. Thank you for developing such elegant, usable, and
extensible code and for sharing it with the community.