API Reference¶
WalkScoreAPI¶
-
class
WalkScoreAPI
(api_key=None, http_client=None, proxy=None, max_retries=None)[source]¶ The Python object which exposes the WalkScore API’s functionality.
- Parameters
api_key (
str
/None
) – The API key provided by WalkScore used to authenticate your application. IfNone
or not specified will default to theWALKSCORE_API_KEY
environment variable if present, andNone
if not.http_client (
HTTPClient
) –The HTTP client instance to use for the execution of requests. If not overridden, will default to urlfetch, requests, pycurl, urllib2 in order based on whether they are available in the environment.
Tip
You can override the HTTP client by supplying a
HTTPClient
instance to the method.proxy (
str
/None
) – The URL to use as an HTTP proxy. Defaults toNone
.max_retries (
int
) – Determines the maximum number of HTTP request attempts to make on network failure before giving up. If not specified, defaults to environment variableBACKOFF_DEFAULT_TRIES
or3
if not available.
-
get_score
(latitude, longitude, address=None, return_transit_score=True, return_bike_score=True, max_retries=None)[source]¶ Retrieve the WalkScore, TransitScore, and/or BikeScore for a given location from the WalkScore API.
- Parameters
latitude (numeric) – The latitude of the location whose score(s) should be retrieved.
longitude (numeric) – The longitude of the location whose score(s) should be retrieved.
address (
str
/None
) – The address whose score(s) should be retrieved. Defaults toNone
.return_transit_score (
bool
) – IfTrue
, will return the location’s TransitScore. Defaults toTrue
.return_bike_score (
bool
) – IfTrue
, will return the location’s BikeScore. Defaults toTrue
.max_retries (
None
/int
) – The maximum number of retries to attempt if the WalkScore API times out or otherwise fails to return a response. IfNone
, will apply the default the configured when initializing the WalkScore API object. To suppress all retries, set to 0. Defaults toNone
.
- Returns
The location’s WalkScore, TransitScore, and BikeScore with meta-data.
- Return type
- Raises
AuthenticationError – if the API key is invalid
ScoreInProgressError – if the score is being calculated and is not currently available
WalkScoreError – if an internal WalkScore API error occurred
QuotaError – if your daily quota has been exceeded
BlockedIPError – if your IP address has been blocked
InvalidCoordinatesError – if your latitude/longitude coordinates are not valid
-
property
http_client
¶ The object instance to use as the HTTP client to make HTTP requests against the WalkScore API.
- Return type
-
property
max_retries
¶ The number of attempts to make on network connectivity-related API failures.
- Return type
LocationScore¶
-
class
LocationScore
(address=None, original_latitude=None, original_longitude=None, status=None, walk_score=None, walk_description=None, walk_updated=None, transit_score=None, transit_description=None, transit_summary=None, bike_score=None, bike_description=None, logo_url=None, more_info_icon=None, more_info_link=None, help_link=None, snapped_latitude=None, snapped_longitude=None, property_page_link=None)[source]¶ Object representation of a location’s scoring data returned from the WalkScore API.
- Parameters
address (
str
/None
) – The address originally supplied to the WalkScore API. Defaults toNone
.original_latitude (numeric /
None
) – The latitude value originally supplied to the WalkScore API. Defaults toNone
.original_longitude (numeric /
None
) – The longitude value originally supplied to the WalkScore API. Defaults toNone
.status (
int
/None
) – The status returned from the WalkScore API. Defaults toNone
.walk_score (
int
/None
) – The WalkScore for the location. Deafults toNone
walk_description (
str
/None
) – An English characterization of the WalkScore, e.g. “Somewhat Walkable”. Defaults toNone
.walk_updated (
datetime
/None
) – The timestamp when the WalkScore was calculated. Defaults toNone
transit_score (
int
/None
) – The TransitScore for the location. Deafults toNone
transit_description (
str
/None
) – An English characterization of the TransitScore, e.g. “Rider’s Paradise”. Defaults toNone
.transit_summary (
str
/None
) – Notes on the transit options accessible from the location. Defaults toNone
.bike_score (
int
/None
) – The BikeScore for the location. Deafults toNone
bike_description (
str
/None
) – An English characterization of the BikeScore, e.g. “Very Bikeable”. Defaults toNone
.logo_url (
str
/None
) – The URL of the WalkScore logo. Defaults toNone
.more_info_icon (
str
/None
) – The URL to the icon to use when linking to more information. Defaults toNone
.more_info_link (
str
/None
) – The URL to link to when providing more information. Defaults toNone
.help_link (
str
/None
) – A link to the “How Walk Score Works” page. Defaults toNone
.snapped_latitude (numeric /
None
) – The latitude for the location, snapped to a grid of approximately 500 ft. by 500 ft. Defaults toNone
.snapped_longitude (numeric /
None
) – The longitude for the location, snapped to a grid of approximately 500 ft. by 500 ft. Defaults toNone
.property_page_link (
str
/None
) – The URL to the walkscore.com map and score for the location. Defaults toNone
.
-
classmethod
from_dict
(obj, api_compatible=False)[source]¶ Create a
LocationScore
instance from adict
representation.- Parameters
- Returns
LocationScore
representation ofobj
.- Return type
-
classmethod
from_json
(obj, api_compatible=False)[source]¶ Create a
LocationScore
instance from a JSON representation.- Parameters
- Returns
LocationScore
representation ofobj
.- Return type
-
to_dict
(api_compatible=False)[source]¶ Serialize the
LocationScore
to adict
.
-
to_json
(api_compatible=False)[source]¶ Serialize the
LocationScore
to a JSON string.
-
property
address
¶ The original address supplied for the
LocationScore
.- Return type
-
property
bike_score
¶ The TransitScore for the location, measuring bike-ability on a scale from 0 to 100.
- Return type
-
property
more_info_icon
¶ URL to the question mark icon to display next to the Score.
- Return type
-
property
more_info_link
¶ URL for the question mark displayed next to the Score to link to.
- Return type
-
property
original_coordinates
¶ The coordinates of the location as originally supplied.
-
property
original_longitude
¶ The longitude of the location as originally supplied.
- Return type
-
property
property_page_link
¶ URL to the walkscore.com score and map for the location.
- Return type
-
property
snapped_coordinates
¶ The coordinates of the location as returned by the API.
-
property
transit_description
¶ A textual description of the location’s ease-of-transit.
- Return type
-
property
transit_score
¶ The TransitScore for the location, measuring ease-of-transit on a scale from 0 to 100.
- Return type
HTTPClient¶
-
class
HTTPClient
(verify_ssl_certs=True, proxy=None)[source]¶ Base class that provides HTTP connectivity.
-
request
(method, url, parameters=None, headers=None, request_body=None)[source]¶ Execute a standard HTTP request.
- Parameters
method (
str
) – The HTTP method to use for the request. Accepts GET, HEAD, POST, PATCH, PUT, or DELETE.url (
str
) – The URL to execute the request against.parameters (
dict
/None
) – URL parameters to submit with the request. Defaults toNone
.headers (
dict
/None
) – HTTP headers to submit with the request. Defaults toNone
.request_body (
None
/dict
/str
/bytes
) – The data to supply in the body of the request. Defaults toNone
.
- Returns
The content of the HTTP response, the status code of the HTTP response, and the headers of the HTTP response.
- Return type
- Raises
ValueError – if
method
is not eitherGET
,HEAD
,POST
,PATCH
,PUT
orDELETE
ValueError – if
url
is not a valid URLValueError – if
headers
is not empty and is not adict
HTTPTimeoutError – if the request times out
SSLError – if the request fails SSL certificate verification
WalkScoreError – or sub-classes for other errors returned by the API
-
request_with_retries
(method, url, parameters=None, headers=None, request_body=None)[source]¶ Execute a standard HTTP request with automatic retries on failure.
- Parameters
method (
str
) – The HTTP method to use for the request. Accepts GET, HEAD, POST, PATCH, PUT, or DELETE.url (
str
) – The URL to execute the request against.parameters (
dict
/None
) – URL parameters to submit with the request. Defaults toNone
.headers (
dict
/None
) – HTTP headers to submit with the request. Defaults toNone
.request_body (
None
/dict
/str
/bytes
) – The data to supply in the body of the request. Defaults toNone
.
Note
This method will apply an exponential backoff strategy to retry the API request if it times out. By default:
requests that can be retried will be retried up to
3
times, but this can be overridden by setting aBACKOFF_DEFAULT_TRIES
environment variable with the maximum number of attempts to makethere is no maximum delay to wait before final failure, but this can be overridden by setting a
BACKOFF_DEFAULT_DELAY
environment variable with the maximum number of seconds to wait (across all attempts) before failing.
- Raises
ValueError – if
method
is not eitherGET
,HEAD
,POST
,PATCH
,PUT
orDELETE
ValueError – if
url
is not a valid URLHTTPTimeoutError – if the request times out after repeated attempts
SSLError – if the request fails SSL certificate verification
WalkScoreError – or sub-classes for other errors returned by the API
-