Skip to main content

Using types

Nested request parameters are TypedDicts. Responses are Pydantic models which also provide helper methods for things like:
  • Serializing back into JSON, model.to_json()
  • Converting to a dictionary, model.to_dict()
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set python.analysis.typeCheckingMode to basic.

Nested params

Nested parameters are dictionaries, typed using TypedDict. Bracketed query parameters in the REST API map to a single keyword argument that takes a dictionary, so filter[country_code]=US becomes filter={"country_code": "US"}. The exception is pagination: on list methods paginated with page[...], page[number] and page[size] are flattened to the page_number and page_size keyword arguments (there is no page= or limit= argument on those methods).
For example:

File uploads

Request parameters that correspond to file uploads can be passed as bytes, or a PathLike instance or a tuple of (filename, contents, media type).
The async client uses the exact same interface. If you pass a PathLike instance, the file contents will be read asynchronously automatically.

Pagination

List methods in the Telnyx API are paginated. This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
Or, asynchronously:
Alternatively, you can use the .has_next_page(), .next_page_info(), or .get_next_page() methods for more granular control working with pages:
Or just work directly with the returned data: