https://github.com/idlesign/pysyge
API to access data from Sypex Geo IP database files from your Python code
https://github.com/idlesign/pysyge
geo geoip python sypexgeo
Last synced: about 2 months ago
JSON representation
API to access data from Sypex Geo IP database files from your Python code
- Host: GitHub
- URL: https://github.com/idlesign/pysyge
- Owner: idlesign
- License: bsd-3-clause
- Created: 2012-06-27T16:15:45.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2024-03-08T08:43:08.000Z (over 1 year ago)
- Last Synced: 2025-04-15T05:47:07.661Z (2 months ago)
- Topics: geo, geoip, python, sypexgeo
- Language: Python
- Size: 65.7 MB
- Stars: 26
- Watchers: 6
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
pysyge
======
http://github.com/idlesign/pysyge|release| |lic| |coverage|
.. |release| image:: https://img.shields.io/pypi/v/pysyge.svg
:target: https://pypi.python.org/pypi/pysyge.. |lic| image:: https://img.shields.io/pypi/l/pysyge.svg
:target: https://pypi.python.org/pypi/pysyge.. |coverage| image:: https://img.shields.io/coveralls/idlesign/pysyge/master.svg
:target: https://coveralls.io/r/idlesign/pysygeWhat's that
-----------*pysyge is an API to access data from Sypex Geo IP database files from your Python code.*
For more information about Sypex Geo databases and their features please visit http://sypexgeo.net.
Direct DB link that might became broken over time:
* Sypex Geo City DB - http://sypexgeo.net/files/SxGeoCity_utf8.zip
Requirements
------------* Python 3.6+
Attention
---------1. This version of pysyge works with **Sypex Geo DB version 2.2 or above**.
The structure of a dictionary returned by GeoLocator.get_location() was preserved in a backward compatible manner
as much as possible, yet it's advised to update your code to use data from `info` sub dictionary.2. This version of pysyge works with **UTF-8** Sypex Geo Databases. Texts returned by pysyge are **UTF-8**.
Quickstart
----------Download Geo IP database file from http://sypexgeo.net/ (example below uses ``SxGeoCityMax.dat`` file).
Application sample
.. code-block:: python
# Import all we need from pysyge module.
from pysyge import GeoLocator, MODE_BATCH, MODE_MEMORY# Create GeoLocator object to access API
# from 'SxGeoCityMax.dat' using fast memory mode.
geodata = GeoLocator('SxGeoCityMax.dat', MODE_BATCH | MODE_MEMORY)# Let's get some meta information.
print('DB version %s (%s)' % (geodata.get_db_version(), geodata.get_db_date()))# Request geo information for 77.88.21.3 IP address.
# Getting detailed information, including region info.
location = geodata.get_location('77.88.21.3', detailed=True)# Print out some lyrics.
# Most interesting data is under `info` in `city`, `country` and `region` dictionaries
print('%s (%s) calling. All the circuits are busy.' % (
location['info']['city']['name_en'], location['info']['country']['iso']))