A simple Python client for the RideWithGPS API.
This project is not affiliated with or endorsed by RideWithGPS.
Note: This client isn't used for a lot yet, so it may not work quite right. Read the code before you use it, and report any bugs you find.
Also Note: The Ride With GPS API is JSON based and under active development. It doesn't have full documentation published, and the best way to figure out how things work is to use the dev tools in your browser to watch actual requests.
- Authenticates with the RideWithGPS API
- Makes any API request,
get
orput
, to the API. - Built-in rate limiting, caching, and pagination.
- Use higher level abstrations like
list
to get collections of things.
RideWithGPS has a new API under development at https://github.com/ridewithgps/developers.
Expect this library to expose the new endpoints with "top level" methods, and OAuth.
Also expect this library to support registering for inbound webhooks from RideWithGPS. Exciting.
The package is published on PyPI.
First, install the package:
pip install pyrwgps
Then, in your Python code:
from pyrwgps import RideWithGPS
# Initialize client and authenticate, with optional in-memory GET cache enabled
client = RideWithGPS(apikey="yourapikey", cache=True)
user_info = client.authenticate(email="your@email.com", password="yourpassword")
print(user_info.id, user_info.display_name)
# Update the name of an activity (trip)
activity_id = "123456"
new_name = "Morning Ride"
response = client.put(
path=f"/trips/{activity_id}.json",
params={"name": new_name}
)
updated_name = response.trip.name if hasattr(response, "trip") else None
if updated_name == new_name:
print(f"Activity name updated to: {updated_name}")
else:
print("Failed to update activity name.")
# We changed something, so probably should clear the cache.
client.clear_cache()
# Simple GET: Get a list of 20 rides for this user (returned as objects)
rides = client.get(
path=f"/users/{user_info.id}/trips.json",
params = {"offset": 0, "limit": 20}
)
for ride in rides.results:
print(ride.name, ride.id)
# Automatically paginate: List up to 25 activities (trips) for this user
for ride in client.list(
path=f"/users/{user_info.id}/trips.json",
params={},
limit=25,
):
print(ride.name, ride.id)
# Automatically paginate: List all gear for this user
gear = {}
for g in client.list(
path=f"/users/{user_info.id}/gear.json",
params={},
):
gear[g.id] = g.nickname
print(gear)
Note:
- All API responses are automatically converted from JSON to Python objects with attribute access.
- You must provide your own RideWithGPS credentials and API key.
- The
list
,get
,put
,post
, anddelete
methods are the recommended interface for making API requests; see the code and RideWithGPS API docs for available endpoints and parameters.
If you use this as VS Dev Container, you can skip using a venv.
python3 -m venv env
source env/bin/activate
pip install .[dev]
Or, for local development with editable install:
git clone https://github.com/ckdake/pyrwgps.git
cd pyrwgps
pip install -e . .[dev]
python -m pytest --cov=pyrwgps --cov-report=term-missing -v
python3 scripts/example.py
Run these tools locally to check and format your code:
-
pylint (static code analysis):
pylint pyrwgps
-
flake8 (style and lint checks):
flake8 pyrwgps
-
black (auto-formatting):
black pyrwgps
-
mypy (type checking):
mypy pyrwgps
If you need to update the VCR cassettes for integration tests:
-
Set required environment variables:
RIDEWITHGPS_EMAIL
RIDEWITHGPS_PASSWORD
RIDEWITHGPS_KEY
Example:
export RIDEWITHGPS_EMAIL=your@email.com export RIDEWITHGPS_PASSWORD=yourpassword export RIDEWITHGPS_KEY=yourapikey
-
Run the integration test to generate a new cassette:
rm tests/cassettes/ridewithgps_integration.yaml python -m pytest --cov=pyrwgps --cov-report=term-missing -v
-
Scrub sensitive data from the cassette:
python scripts/scrub_cassettes.py
- This will back up your cassettes to
*.yaml.original
(if not already present). - The sanitized cassettes will overwrite
*.yaml
.
- This will back up your cassettes to
-
Re-run tests to verify:
python -m pytest --cov=pyrwgps --cov-report=term-missing -v
To publish a new version of this package to PyPI:
-
Update the version number
Editpyproject.toml
and increment the version. -
Install build tools
pip install .[dev]
-
Build the distribution
python -m build
This will create
dist/pyrwgps-<version>.tar.gz
and.whl
files. -
Check the distribution (optional but recommended)
twine check dist/*
-
Upload to PyPI
twine upload dist/*
You will be prompted for your PyPI API key.
-
Open your package on PyPI (optional)
$BROWSER https://pypi.org/project/pyrwgps/
Note:
- Configure your
~/.pypirc
is configured if you want to avoid entering credentials each time. - For test uploads, use
twine upload --repository testpypi dist/*
and visit TestPyPI.
MIT License
This project is not affiliated with or endorsed by RideWithGPS.