Skip to content

Context manager support #28

@hongquan

Description

@hongquan

It would be more Pythonic if you guys support Python's context manager for geoip2.database.Reader, so that we can call:

with geoip2.database.Reader('GeoLite2-City.mmdb') as reader:
    r = reader.city(ip_addr)
    data = {
        'country_code': r.country.iso_code,
        'country_name': r.country.name
    }

and reader.close() is called automatically when exiting with.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions