package maxminddb

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Maxmind is a binding to libmaxminddb with some higher level functionality on the OCaml side. Be aware that operations with the C side are liable to raise exceptions

type mmdb

Abstract type representing the C side pointer to a mmdb database in memory

type location = {
  1. latitude : float;
  2. longitude : float;
  3. metro_code : int;
  4. time_zone : string;
}

Type representing physical location data

type borders = {
  1. postal_code : string;
  2. city_name : string;
  3. country_name : string;
  4. continent_name : string;
  5. iso_code : string;
}

Type representing political borders of an IP address

type languages =
  1. | German
  2. | English
  3. | Spanish
  4. | French
  5. | Japanese
  6. | Brazilian
  7. | Russian
  8. | Chinese

Languages that Maxmindb DB knows for paths ending in string queries, note that not all queries support all languages

type query_r = [
  1. | `String of string
  2. | `Int of int
  3. | `Float of float
  4. | `Bool of bool
]

Result of a query, mostly relevant if you are doing it by hand with calls to lookup_path

val version : unit -> string

Get version string of Maxminddb

val create : path:string -> mmdb

Create a handle on a mmdb descriptor based off a .mmdb database file. Maxminddb comes with City, Country databases in etc

val close : mmdb -> unit

Close a handle on a mmdb descriptor, raises exception if you try to use the handle after you called closed on it.

val dump : ?ip:string -> mmdb -> string

Dumps the database as a string; if ip is provided then dumps the database for this particular ip address, if no ip provided then dumps Metainformation about the database itself. Note that you should do not depend on this structure: it is not JSON, just looks like it.

val lookup_path : ip:string -> query:string list -> mmdb -> query_r

For a given ip address, think 127.0.0.1, query path and mmdb handle, get the result. Note path must be safe, look at dump first

val postal_code : ip:string -> mmdb -> string

Short cut function for getting postal code from ip address

val city_name : ?lang:languages -> ip:string -> mmdb -> string

Short cut function for getting a city name from ip address

val country_name : ?lang:languages -> ip:string -> mmdb -> string

Short cut function for getting a country name from ip address

val continent_name : ?lang:languages -> ip:string -> mmdb -> string

Short cut function for getting a continent name from ip address

val location : ip:string -> mmdb -> location

Short cut function for getting a record of physical location information

val iso_code : ip:string -> mmdb -> string

ISO code for Country of IP address

val borders_dump : ?lang:languages -> ip:string -> mmdb -> borders

Shortcut providing top level geographical information

val with_mmdb : path:string -> (mmdb -> unit) -> unit

Convenience function that opens and closes a mmdb for you

OCaml

Innovation. Community. Security.