TFL Client
A client to interact with the TFL API.
The TFLClient
class is a subclass of httpx.AsyncClient that is used
to interact with the TFL API. Using the TFLClient
class, you can send requests to the TFL API.
The TFLClient
allows for the Auth
class to be passed in as an argument. This will add the API key to the request
URL as a query parameter. If no Auth
class is passed in, the request will be sent without an API key. This will
result in a rate limit of 50 requests per hour.
Also, the base_url
is set to the TFL API base URL. This means that when a request is sent, the URL will be appended
to the base URL. For example, if the base_url
is set to https://api.tfl.gov.uk/
, and the request URL is set to
Disruptions/Lifts/v2
, the request URL will be https://api.tfl.gov.uk/Disruptions/Lifts/v2
.
Using the TFLClient
, you can access all of TFL API through handlers. For example, to access the Lift Disruptions
V2 API, you can use the LiftDisruptionsV2Handler
:
from tfl import clients
async with clients.TFLClient() as client:
response = await client.handlers.lift_disruptions_v2_handler.get_lift_disruptions()
print(response.json())
Check out Handlers for more information on the available handlers.
TFLClient
¶
Bases: httpx.AsyncClient
Client to interact with the TFL API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auth |
Optional[Auth]
|
TFL authentication class to use when sending requests. |
None
|
params |
Optional[QueryParamTypes]
|
Query parameters to include in request URLs, as a string, dictionary, or sequence of two-tuples. |
None
|
headers |
Optional[HeaderTypes]
|
Dictionary of HTTP headers to include when sending requests. |
None
|
cookies |
Optional[CookieTypes]
|
Dictionary of Cookie items to include when sending requests. |
None
|
verify |
VerifyTypes
|
SSL certificates (a.k.a CA bundle) used to verify the identity of requested hosts. Either |
True
|
cert |
Optional[CertTypes]
|
An SSL certificate used by the requested host to authenticate the client. Either a path to an SSL certificate file, or two-tuple of (certificate file, key file), or a three-tuple of (certificate file, key file, password). |
None
|
proxies |
Optional[ProxiesTypes]
|
A dictionary mapping proxy keys to proxy URLs. |
None
|
timeout |
TimeoutTypes
|
The timeout configuration to use when sending requests. |
DEFAULT_TIMEOUT_CONFIG
|
limits |
Limits
|
The limits configuration to use. |
DEFAULT_LIMITS
|
max_redirects |
int
|
The maximum number of redirect responses that should be followed. |
DEFAULT_MAX_REDIRECTS
|
transport |
Optional[AsyncBaseTransport]
|
A transport class to use for sending requests over the network. |
None
|
app |
Optional[Callable[..., Any]]
|
An WSGI application to send requests to, rather than sending actual network requests. |
None
|
trust_env |
bool
|
Enables or disables usage of environment variables for configuration. |
True
|
default_encoding |
Union[str, Callable[[bytes], str]]
|
The default encoding to use for decoding response text, if no charset information is included in a response Content-Type header. Set to a callable for automatic character set detection. Default: "utf-8". |
'utf-8'
|