python-2gis¶
python-2gis is a python (and pythonic) library for accessing the 2GIS API.
Contents¶
Installation¶
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)
Firms search¶
Documentation: http://api.2gis.ru/doc/firms/searches/search/
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 rubrics:
api.search(what=u'пиво', where=u'Иркутск')
Search for firms and rubrics in radius of 1000 m from a point:
api.search(what=u'пиво', point=[104.281352, 52.287771], radius=1000)
Search for firms and rubrics in a bounds:
api.search(what=u'пиво', bound=[[82.801886, 54.991984], [82.9019, 52.9910]])
Search with worktime filter:
filters = {
'worktime': 'mon,23:01',
}
api.search(what=u'пиво', where=u'Иркутск', filters=filters)
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
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)