Speeding up Python with Rust: GeoIP Lookup Database as a case study.

Abhijit Gadgil (~gabhijit)




In order to perform GeoIP Lookup, there are databases like maxmind available, which allow one to map an IP address to a given country. In this talk we explore an approach to implement such a database using first principles in Python and then take a look at how this implementation can be speeded up using Rust and Python bindings for the Rust library using pyo3.

The talk is organized into following three sections -

  1. Overview of GeoIP Database Lookup Implementation (5 minutes)

    • Internet, Autonomous Systems and BGP Updates
    • Publicly available datasets, to obtain the required data that is -
      • Prefix data
      • Autonomous Systems to Organizations and Organizations to Country Data.
    • Routing Table and Longest Prefix Match
  2. Implementation of above routing table and other utils in Rust with available Pythonic APIs and performance comparison (20 minutes)

    • An implementation of a Routing Table to perform longest prefix match for an Input IP Address in Python (And using numpy.dtype)
    • Same implementation in Rust with Python Bindings
      • pybgpkit_parser (public PyPI package)
      • route_table ( We will discuss in details this implementation)
  3. Performance Comparison of the two approaches (5 minutes)

Audience should expect to understand the following -

  1. Understand about how internet works
  2. Basic implementation of parsing structured data in Python (python struct module)
  3. Simple implementation of Longest Prefix Match and a routing table.
  4. An overview of Rust and pyo3.


None. This is an intermediate level talk with lot of Python (and Rust) code. The aim is also not to provide a tutorial on pyo3 per se. But we will touch upon enough intro to help understand the code.

Content URLs:

  1. Public Datasets

  2. Code

  3. Slides

Speaker Info:

Software developer with experience at several layers of abstraction. Python is my GoTo language to experiment with ideas and Rust is my most favorite language. I have been a speaker at previous Pycon India conferences. I work as a freelance software developer through my consultancy company hyphenOs Software Labs

Speaker Links:

Links to slides for my previous Pycon Talks

  1. Call, Raise or Fold running poker simulations in Python.
  2. Python and cffi visualizing network traces

Social Links:

Section: Networking and Security
Type: Talks
Target Audience: Intermediate
Last Updated: