Skip to main content

A Python client for Mapbox services

Project description

https://travis-ci.org/mapbox/mapbox-sdk-py.png https://coveralls.io/repos/mapbox/mapbox-sdk-py/badge.png

A Python client for Mapbox web services

Services

  • Geocoding

    • Forward (place names ⇢ longitude, latitude)

    • Reverse (longitude, latitude ⇢ place names)

  • Other services coming soon

Installation

$ pip install mapbox

API Usage

To begin geocoding, import the mapbox module and create a new Geocoder object with your Mapbox access token.

import mapbox

geocoder = mapbox.Geocoder(access_token='YOUR_ACCESS_TOKEN')

Geocoder’s methods return Requests style response objects.

response = geocoder.forward('Chester, NJ')

# response.json() returns the geocoding result as GeoJSON.
# response.status_code returns the HTTP API status code.

response = geocoder.reverse(lon=-74.7083, lat=40.7851)

See import mapbox; help(mapbox.Geocoder) for more detailed usage.

Command Line Interface

The mapbox module includes a CLI program named mbx.

$ mbx --help
Usage: mbx [OPTIONS] COMMAND [ARGS]...

  This is the command line interface to Mapbox web services.

  Mapbox web services require an access token. Your token is shown on the
  https://www.mapbox.com/developers/api/ page when you are logged in. The
  token can be provided on the command line

    $ mbx --access-token MY_TOKEN ...

  or as an environment variable named MAPBOX_ACCESS_TOKEN or
  MapboxAccessToken.

    $ export MAPBOX_ACCESS_TOKEN=MY_TOKEN
    $ mbx ...

Options:
  --access-token TEXT  Your Mapbox access token.
  -v, --verbose        Increase verbosity.
  --version            Show the version and exit.
  -q, --quiet          Decrease verbosity.
  --help               Show this message and exit.

Commands:
  geocode  Geocode an address or coordinates.

The mbx-geocode command can do forward or reverse geocoding.

$ mbx geocode --help
Usage: mbx geocode [OPTIONS] [QUERY]

  This command returns places matching an address (forward mode) or places
  matching coordinates (reverse mode).

  In forward (the default) mode the query argument shall be an address such
  as '1600 pennsylvania ave nw'.

    $ mbx geocode '1600 pennsylvania ave nw'

  In reverse mode the query argument shall be a JSON encoded array of
  longitude and latitude (in that order) in decimal degrees.

    $ mbx geocode --reverse '[-77.4371, 37.5227]'

  An access token is required, see `mbx --help`.

Options:
  --forward / --reverse  Perform a forward or reverse geocode. [default:
                         forward]
  -i, --include          Include HTTP headers in the output.
  --lat FLOAT            Bias results toward this latitude (decimal degrees).
                         --lon is also required.
  --lon FLOAT            Bias results toward this longitude (decimal degrees).
                         --lat is also required.
  -t, --place-type NAME  Restrict results to one or more of these place types:
                         ['address', 'country', 'place', 'poi', 'postcode',
                         'region'].
  -o, --output TEXT      Save output to a file.
  --help                 Show this message and exit.

Its output can be piped to geojsonio using geojsonio-cli.

$ mbx geocode 'Chester, NJ' | geojsonio

Testing

pip install -e .[test]
py.test

See Also

https://github.com/mapbox/mapbox-sdk-js

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mapbox-0.2.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distributions

mapbox-0.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

mapbox-0.2.0-py2-none-any.whl (9.7 kB view details)

Uploaded Python 2

File details

Details for the file mapbox-0.2.0.tar.gz.

File metadata

  • Download URL: mapbox-0.2.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mapbox-0.2.0.tar.gz
Algorithm Hash digest
SHA256 88e12321aa4f0adccb682e43e2c0b6dfd0cc4fe4c9cd48215ba5a33e02b1b923
MD5 c762493445508031f629dde4cf5281a8
BLAKE2b-256 1fb6d0e375f43e7bc55b3363daf19331aa6482613470b8510692ddf95d780bb1

See more details on using hashes here.

File details

Details for the file mapbox-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mapbox-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c69dd47d37e4cf5b871efa8159a439b827edfa5c23f49f6af52ee14eb49c6288
MD5 3d2d45d05202c1665f85f6d65a2393cc
BLAKE2b-256 22e085a78c855724d4f7fdae186a005a5e6204f4e7bbc20c58387f3da56a3095

See more details on using hashes here.

File details

Details for the file mapbox-0.2.0-py2-none-any.whl.

File metadata

File hashes

Hashes for mapbox-0.2.0-py2-none-any.whl
Algorithm Hash digest
SHA256 58dfe939e62e15c1a1e30b429866e4a8935056556c3167c6da0d74c4e39fca03
MD5 b23ef46b24e987d59a0186708f984046
BLAKE2b-256 41c979e81c2b781f5ad6badad2348fca9400812611874a648bff16a8db37dec9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page