IPScope .mmdb files conform strictly to the MaxMind DB binary format v2.0 specification. Open the reader once at process startup and share it across requests; lookups read from mmap memory in under a microsecond.
import maxminddb
with maxminddb.open_database("/var/lib/ipscope/ipscope-complete.mmdb") as reader:
record = reader.get("198.51.100.7")
if record is not None:
print(record["geo"]["country_code"], record["security"]["is_vpn"])# Command-line inspection (`mmdblookup`)
mmdblookup --file /var/lib/ipscope/ipscope-complete.mmdb --ip 198.51.100.7