{"id":5077,"library":"telnyx","title":"Telnyx Python Library","description":"The Telnyx Python library provides convenient access to the Telnyx REST API from any Python 3.9+ application. It includes type definitions for all request parameters and response fields, offering both synchronous and asynchronous clients powered by `httpx`. The library is actively maintained with frequent updates, often daily, reflecting API changes and new features.","status":"active","version":"4.105.1","language":"en","source_language":"en","source_url":"https://github.com/team-telnyx/telnyx-python","tags":["telecom","sms","voice","api-client","call-control","webhooks","ai"],"install":[{"cmd":"pip install telnyx","lang":"bash","label":"Standard Install"},{"cmd":"pip install telnyx[aiohttp]","lang":"bash","label":"Install with aiohttp for async client"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false},{"reason":"Optional backend for improved concurrency performance with the async client.","package":"aiohttp","optional":true}],"imports":[{"note":"For synchronous API calls.","symbol":"Telnyx","correct":"from telnyx import Telnyx"},{"note":"For asynchronous API calls.","symbol":"AsyncTelnyx","correct":"from telnyx import AsyncTelnyx"}],"quickstart":{"code":"import os\nimport telnyx\n\n# It is recommended to set TELNYX_API_KEY as an environment variable\n# export TELNYX_API_KEY=\"YOUR_TELNYX_API_KEY\"\napi_key = os.environ.get(\"TELNYX_API_KEY\", \"YOUR_TELNYX_API_KEY_HERE\")\n\nif not api_key or api_key == \"YOUR_TELNYX_API_KEY_HERE\":\n    print(\"Warning: TELNYX_API_KEY environment variable not set or is placeholder.\")\n    print(\"Please set TELNYX_API_KEY or replace 'YOUR_TELNYX_API_KEY_HERE' with your actual API key.\")\n    # In a production environment, you would likely exit or raise an error.\n\nclient = telnyx.Telnyx(api_key=api_key)\n\ntry:\n    # Example: List messaging profiles to verify connectivity and API key\n    print(\"Attempting to list messaging profiles...\")\n    messaging_profiles = client.messaging_profiles.list()\n    print(f\"Successfully retrieved {len(messaging_profiles.data)} messaging profiles.\")\n    if messaging_profiles.data:\n        print(f\"First profile ID: {messaging_profiles.data[0].id}\")\n\nexcept telnyx.APIStatusError as e:\n    print(f\"Telnyx API Error: {e.status_code} - {e.response.json()}\")\n    print(\"Please ensure your API key is valid and has the necessary permissions.\")\nexcept telnyx.APIConnectionError as e:\n    print(f\"Telnyx Connection Error: {e}\")\n    print(\"Please check your network connection.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"Initializes the Telnyx client using an API key from an environment variable and attempts to list messaging profiles to verify connectivity and authentication. Replace `YOUR_TELNYX_API_KEY_HERE` with an actual key or ensure the `TELNYX_API_KEY` environment variable is set."},"warnings":[{"fix":"Immediately uninstall the affected versions (`pip uninstall telnyx`), then install a known clean version (e.g., `pip install telnyx==4.87.0` or the latest stable version not affected). Rotate all exposed credentials and audit systems for compromise.","message":"Malicious versions 4.87.1 and 4.87.2 were briefly published to PyPI, containing malicious code. If installed between 03:51 UTC and 10:13 UTC on March 27, 2026, your system may have been compromised.","severity":"breaking","affected_versions":"4.87.1, 4.87.2"},{"fix":"Use `api_key=os.environ.get(\"TELNYX_API_KEY\")` when instantiating `telnyx.Telnyx()` or `telnyx.AsyncTelnyx()`. Never hardcode API keys or commit them to version control.","message":"Telnyx recommends storing API keys as environment variables (`TELNYX_API_KEY`) and explicitly passing them to the client constructor, rather than setting `telnyx.api_key` globally, especially for applications requiring multiple keys or robust security practices.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement Ed25519 webhook signature verification in your webhook handler. Refer to the Telnyx documentation for specific implementation details for Python.","message":"Webhook signature verification now defaults to Ed25519. If you are handling webhooks, it's strongly recommended to verify signatures to ensure authenticity.","severity":"gotcha","affected_versions":"4.105.0 and newer"},{"fix":"Regularly review release notes before upgrading and thoroughly test your application after updates to catch subtle breaking changes.","message":"The library is updated very frequently (sometimes daily), and while it generally follows SemVer, some backwards-incompatible changes may be released as minor versions if they affect static types, internal components, or are not expected to impact the majority of users.","severity":"gotcha","affected_versions":"All versions (v4 and above)"},{"fix":"When an API parameter clashes with a Python reserved word, append an underscore (`_`) to the parameter name (e.g., `from_=\"...\"`).","message":"The keyword `from` is a reserved word in Python but often an API parameter (e.g., in messaging). The library handles this by allowing `from_` as a keyword argument for such parameters.","severity":"gotcha","affected_versions":"All versions (where 'from' is an API parameter)"},{"fix":"Ensure your file upload logic conforms to the latest SDK examples for `telnyx.files.create()` or similar methods to avoid issues fixed in v4.104.1.","message":"When sending file data, ensure it is passed as a single parameter. An earlier bug caused issues if file data was incorrectly structured.","severity":"gotcha","affected_versions":"Prior to 4.104.1"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}