libloc comes with native Python bindings which are used by its main command-line tool location . They are the most advanced bindings as they support reading from the database as well as writing to it.

Man Page
Python
Load the database
>>> import location
>>> d = location.Database("/var/lib/location/database.db")
Search for an Autonomous System by Name
>>> for i in d.search_as("Lightning Wire Labs"):
...   print(i)
...
AS204867 - Lightning Wire Labs GmbH
Lookup an IP Address
>>> n = d.lookup("81.3.27.38")
>>> n
<location.Network 81.3.0.0/18>
>>> n.asn
24679
>>> n.country_code
'DE'