python-2gis

python-2gis is a python (and pythonic) library for accessing the 2GIS API.

Contents

Installation

Easy way

Just install it with pip:

pip install 2gis

or easy_install:

easy_install 2gis

Sources

Sources is available on GitHub.

Clone the public repository:

git clone git://github.com/svartalf/python-2gis.git

Download the tarball:

$ curl -OL https://github.com/svartalf/python-2gis/tarball/master

Or, download the zipball:

$ curl -OL https://github.com/svartalf/python-2gis/zipball/master

Once you have a copy of the source, you can embed it in your Python package, or install it into your site-packages easily:

$ python setup.py install

Usage

Using a 2GIS API is very simple.

Begin with importing dgis module

>>> import dgis

Create an API object and give to it your unique API key

>>> api = dgis.API('1234567890')

You can call all the 2GIS API methods like this

>>> projects = api.project_list()

Now, projects is a big list with all available projects.

All parameters for 2GIS API endpoints are passed as an keyword arguments to the respective library’ methods

>>> cities = api.city_list(project_id=11)

You should not pass parameters output, callback, key and version to all the methods, library do this internally.

API endpoints

Projects

Documentation: http://api.2gis.ru/doc/firms/list/project-list/

No parameters is allowed.

Examples
api.project_list()
Cities

Documentation: http://api.2gis.ru/doc/firms/list/city-list/

Allowed parameters:

  • where
  • project_id
Examples

Searching by city name:

api.city_list(where=u'Иркутск')

Searching by project id:

api.city_list(project_id=11)
Rubricator

Documentation: http://api.2gis.ru/doc/firms/list/rubricator/

Allowed parameters:

  • where
  • id
  • parent_id
  • show_children
  • sort
Examples

All rubrics related to the city:

api.rubricator(where=u'Новосибирск')

Get information about a one rubric:

api.rubricator(id=1234567890)

Get all child rubrics:

api.rubricator(parent_id=1234567890)

Get rubric with all the children

api.rubricator(id=1234567890, show_children=True)
Search in rubric

Documentation: http://api.2gis.ru/doc/firms/searches/searchinrubric/

Allowed parameters:

  • what
  • where
  • point : list of two coordinates [lon, lat]
  • radius
  • bound : [[lon1, lat1], [lon2, lat2]]
  • page
  • pagesize
  • sort
  • filters
Examples

Search for firms and rubric:

api.search(what=u'Окна', where=u'Иркутск')
Firm filials

Documentation: http://api.2gis.ru/doc/firms/searches/firmsbyfilialid/

Allowed parameters:

  • firmid
  • page
  • pagesize
Examples
api.firms_by_filial_id(firmid=1234567890)
api.firms_by_filial_id(firmid=1234567890, page=2, pagesize=5)

Indices and tables