Python utilities used for interacting with Locations
Project description
Christopher H. Todd's Python Library For Interacting With Locations
The ctodd-python-lib-location project is responsible for manging location information, geocoding addresses, and getting directions.
Table of Contents
Dependencies
Python Packages
- geocoder==1.38.1
- requests==2.22.0
- street-address==0.4.0
- usaddress==0.5.10
Libraries
address_helpers.py
Address Helpers. This library is used to interact with address strings/dicts and convert/handle these addresses.
Functions:
def convert_string_address_to_dict(address_string, expected_fields=None):
"""
Purpose:
Parse a string into an address dict with specific fields
Args:
address_string (String): Raw address string to try and parse
expected_fields (List): List of fields that are needed to be parsed to be
considered successful
Return:
parsed_address (Dict): Dict of the parsed address with fields that could be
determined from a string
"""
def parse_address_using_lib_usaddress(address_string):
"""
Purpose:
Use the usaddress library to parse a string into a dict
Args:
address_string (String): Raw address string to try and parse
Return:
parsed_address (Dict): Dict of the parsed address with fields that could be
determined from a string
"""
def parse_address_using_lib_streetaddress(address_string):
"""
Purpose:
Use the street-address library to parse a string into a dict
Args:
address_string (String): Raw address string to try and parse
Return:
parsed_address (Dict): Dict of the parsed address with fields that could be
determined from a string
"""
mapquest_helpers.py
Mapquest Helpers. This library is used to wrap mapquest API calls and handle authentication
Functions:
def get_mapquest_api_key(public_key_file="~/.mapquest/public_key.txt"):
"""
Purpose:
Get the mapquest API from the environment
Args:
public_key_file (String): filename of the public key token file
Return:
mapquest_api_key (String): MapQuest public key
"""
def get_directions_between_two_addresses(mapquest_api_key, address_1, address_2):
"""
Purpose:
Get directions between two addresses
Leverages Mapquest API:
https://developer.mapquest.com/documentation/directions-api/route/get/
Args:
address_1 (String): Address to use as start point of travel
address_2 (String): Address to use as end destination of travel
Return:
directions (Dict): Dict of the directions between the two locations
"""
Example Scripts
Example executable Python scripts/modules for testing and interacting with the library. These show example use-cases for the libraries and can be used as templates for developing with the libraries or to use as one-off development efforts.
parse_addresses.py
Purpose:
Parse some set addresses
Steps:
- Parse Args
- Call libs to parse addresses
function call:
python3.6 parse_addresses \
[-h] \
--addresses ADDRESSES
example script call:
python3.6 example_usage/parse_addresses.py \
--address="REDACTED" \
--address="REDACTED"
get_directions_between_addresses.py
Purpose:
Get Directions between two addresses.
Steps:
- Parse Args
- Call libs to get directions from args
- Parse directions for some valuable information
function call:
python3.6 get_directions_between_addresses.py \
[-h] \
--start-address START_ADDRESS \
--end-address END_ADDRESS
example script call:
python3.6 example_usage/get_directions_between_addresses.py \
--start-address="REDACTED" \
--end-address="REDACTED"
Notes
- Relies on f-string notation, which is limited to Python3.6. A refactor to remove these could allow for development with Python3.0.x through 3.5.x
TODO
- Unittest framework in place, but lacking tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ctodd-python-lib-location-1.0.0.tar.gz
.
File metadata
- Download URL: ctodd-python-lib-location-1.0.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a698a5e116ebcba25881c797615e2baaf74a86f5836393fd2291440053dbc43 |
|
MD5 | 0e3d8ceb0e01dd65404b0692537b0dcb |
|
BLAKE2b-256 | f19028f6eba25ff94979b0b8a6217b3d02ae74a65a8f8af535c17be810c6bcd2 |
File details
Details for the file ctodd_python_lib_location-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: ctodd_python_lib_location-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a483b806635a913538d3a24518ac67fe5967ea83adafb9572284c79098370e5 |
|
MD5 | 2b7e0e948bb9e4366ec5081108249a00 |
|
BLAKE2b-256 | 8921df3c08ea379dcd8e26a0a4d12aa2fa8fe7580ea784c4b4e3ba748ada7d50 |