The google python package

by shuba

ModuleNotFound: google

I was messing around with MTA data in an attempt to build widgets that help me not waste time on transit.

I was poking around the nice utilities library called underground to see how this works. The MTA's website links to api endpoints that return protobuf data. Reading on the MTA website and the protobuf documentation site for five minutes did not make it clear how to read this data simply, so I went to Github because surely a billion people have done this before me.

I wanted to find the parts of the code I needed so I could keep my script as minimal as possible. Although, to the credit of the developers of the underground package, it's already pretty minimal. I started by installing the dependencies from the setup.py file in the underground library and tried importing them:

uv init uv add requests uv add google source .venv/bin/activate python3 -c "import google" Traceback (most recent call last): File "<string>", line 1, in <module> import google ModuleNotFoundError: No module named 'google'

I looked at site packages to see what was installed:

ls .venv/lib/python3.13/site-packages | grep google google-3.0.0.dist-info googlesearch

So there's no google package that's installed after running uv add google, just the dependencies.

Instead, I needed to install the gtfs-realtime-bindings package, after which site packages showed a google directory with the transit and protobuf libraries nested inside: ls .venv/lib/python3.13/site-packages/google/ _upb protobuf transit Once this was installed I was able to read the protobuf like this: ``` from google.transit import gtfs_realtime_pb2 import requests

feed = gtfs_realtime_pb2.FeedMessage() feed.ParseFromString(requests.get(MTA_SUBWAY_ENDPOINT).content) feed.ListFields() ```