Code Monkey home page Code Monkey logo

pysyge's Introduction

pysyge

http://github.com/idlesign/pysyge

https://badge.fury.io/py/pysyge.png https://pypip.in/d/pysyge/badge.png

What'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 links that might became broken over time:

Requirements

Python 2.7+, 3.2+

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.
  1. 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:

# Import all we need from pysyge module.
from pysyge.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']))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.