Lookup country code (iso 3166) by IP address.
$ pip install ip2country
Or
$ python setup.py install
You must implement IStore interface in ip2country/interfaces.py.
There is a sample implementation in example/store. This implementation is stored all records on the system memory.
store = Store()
parser = Parser(store)
with open(RECORD_FILE) as fp:
parser.do(fp)
See examples/lookup.py:load for more detail.
store = Store()
record = store.lookup(IP_ADDRESS)
if record is None:
print('Record not found')
else:
print('{0} is allocated to {1}'.format(IP_ADDRESS, record.cc))
See examples/lookup.py:main for more detail.
$ tox
ip2country is licensed under the MIT LICENSE. See ./LICENSE.rst.