Skip to main content

Client interface for the Citybikes API

Project description

python-citybikes

https://travis-ci.org/eskerda/python-citybikes.svg?branch=master

python-citybikes is a python client for the Citybikes API.

About Citybikes

Citybikes is a project about making bike sharing data available to both users and developers. It has a nice and easy to use API, but this package might be useful to projects consuming the API.

python-citybikes must not be confused with pybikes:

  • pybikes is a set of tools to access bike sharing data directly from the providers. It’s the library powering the project and the API. If a network is not supported or does not correctly work, it’s there where the issue or the contribution must be sent.

  • python-citybikes is a python wrapper around the Citybikes API.

Installation

$ pip install python-citybikes

Usage

First instantiate a client

>>>> import citybikes
>>>> client = citybikes.Client()

Get the full list of networks

>>>> networks = list(client.networks)
>>>> len(networks)
458
>>>> networks[0]
{'name': 'Opole Bike', 'href': '/v2/networks/opole-bike', 'location': {'lat
itude': 50.6645, 'city': 'Opole', 'country': 'PL', 'longitude': 17.9276}, '
id': 'opole-bike', 'company': ['Nextbike GmbH']}

Get stations from a network

>>>> len(networks[0].stations)
16
>>>> list(networks[0].stations)[0]
{'timestamp': '2016-11-22T16:05:44.318000Z', 'id': 'd8c9f66260759aeb27445b2
cddf2d6b9', 'name': 'Pętla Autobusowa - Dambonia', 'free_bikes': 7, 'empty_
slots': 3, 'latitude': 50.661775266224, 'extra': {'bike_uids': ['60128', '6
0108', '60063', '60062', '60052', '60037', '60190'], 'number': '6011', 'slo
ts': 10, 'uid': '132115'}, 'longitude': 17.888891100884}

Instantiate a network by id directly

>>>> bicing = citybikes.Network(client, uid='bicing')
>>>> bicing['name']
'Bicing'
>>>> len(bicing.stations)
465

Get a network ordered by distance to lat, lng

>>>> # Lets get the nearest network to NY lat, lng
>>>> net, dist = next(iter(client.networks.near(40.7128, -74.0059)))
>>>> net
{'href': '/v2/networks/citi-bike-nyc', 'id': 'citi-bike-nyc', 'gbfs_href':
'https://gbfs.citibikenyc.com/gbfs/gbfs.json', 'location': {'latitude': 40.
7143528, 'country': 'US', 'longitude': -74.00597309999999, 'city': 'New Yor
k, NY'}, 'company': ['NYC Bike Share, LLC', 'Motivate International, Inc.',
'PBSC Urban Solutions'], 'name': 'Citi Bike'}

Get stations from a network ordered by distance to lat, lng

>>>> # Now, get stations ordered by distance to Manhattan center
>>>> sts = net.stations.near(40.7831, -73.9712)
>>>> for s, dist in sts[:5]:
...     print(s['name'])
...
W 82 St & Central Park West
Central Park West & W 85 St
W 84 St & Columbus Ave
Central Park West & W 76 St
W 89 St & Columbus Ave

History

0.2.0 (2021-02-07)

  • Accept headers on client init

  • Remove user-agent argument (superseded by headers)

0.1.4 (2019-07-26)

  • Fix python 2 compatibility

0.1.3 (2017-02-13)

  • Add JSON Encoder for resources

0.1.1 (2016-11-22)

  • Improve docs

  • near helpers also return relative distance

0.1.0 (2016-11-17)

  • First release

  • Can navigate the Citybikes API

  • Requests for resources are done only once

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

python-citybikes-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

python_citybikes-0.2.0-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python-citybikes-0.2.0.tar.gz.

File metadata

  • Download URL: python-citybikes-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for python-citybikes-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f894cd7b7c91a77ea23daa4a9e6b663aee29b70764388ed37fd7f5892e33ebd3
MD5 4df4970d59853992b6974f6d1e42983e
BLAKE2b-256 d030075d17f85894c9581674cd5dc03912f99bf6c60e8931dceca79bb31f4010

See more details on using hashes here.

File details

Details for the file python_citybikes-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: python_citybikes-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for python_citybikes-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fc2528bb0c042590aca745128dca4925f04873d22369a203c848fe81178109be
MD5 8e83d89e3aec5d28a2f5440dd1efc5d4
BLAKE2b-256 99832307f999134d78f0d18c500247e783e0d14a1561be002743b33c59b2b1b3

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