Skip to main content

Python library to manipulate Open Travel Data

Project description

Minimalist GeoBases implementation:

  • no dependencies

  • compatible with Python 3.6+, CPython and PyPy

  • one data source: opentraveldata

  • one Python module for easier distribution on clusters (like Hadoop)

  • faster load time (5x)

  • tested with pytest and tox

>>> from neobase import NeoBase
>>> b = NeoBase()
>>> b.get('ORY', 'city_code_list')
['PAR']
>>> b.get('ORY', 'city_name_list')
['Paris']
>>> b.get('ORY', 'country_code')
'FR'
>>> b.distance('ORY', 'CDG')
34.87...
>>> b.get_location('ORY')
LatLng(lat=48.72..., lng=2.35...)

Installation

Use the Python package:

pip install neobase

Docs

Check out readthedocs for the API.

You can customize the source data when initializing:

with open("file.csv") as f:
    N = NeoBase(f)

Otherwise the loaded file will be the embedded one, unless the OPTD_POR_FILE environment variable is set. In that case, it will load from the path defined in that variable.

You can manually retrieve the latest data source yourself too, but you expose yourself to some breaking changes if they occur in the data.

from io import StringIO
from urllib.request import urlopen

from neobase import NeoBase, OPTD_POR_URL

data = urlopen(OPTD_POR_URL).read().decode('utf8')
N = NeoBase(StringIO(data))
N.get("PAR")

The reference date of validity can be changed as well:

N = NeoBase(date="2000-01-01")
N.get("AIY")  # was decommissioned in 2015

By default, the reference date will be set to today, unless the OPTD_POR_DATE environment variable is set. In that case, it will use that value.

You can customize the behavior regarding duplicates: points sharing the same IATA code, like NCE as airport and NCE as city. By default everything is kept, but you can set it so that only the first point with an IATA code is kept:

N = NeoBase(duplicates=False)
len(N)  # about 10,000 "only"

Note that you can use the OPTD_POR_DUPLICATES environment variable to control this as well: set it to 0 to drop duplicates.

Finally, you can customize fields loaded by subclassing.

class SubNeoBase(NeoBase):
    KEY = 0  # iata_code

    # Those loaded fields are the default ones
    FIELDS = (
        ("name", 6, None),
        ("lat", 8, None),
        ("lng", 9, None),
        ("page_rank", 12, lambda s: float(s) if s else None),
        ("country_code", 16, None),
        ("country_name", 18, None),
        ('continent_name', 19, None),
        ("timezone", 31, None),
        ("city_code_list", 36, lambda s: s.split(",")),
        ('city_name_list', 37, lambda s: s.split('=')),
        ('location_type', 41, None),
        ("currency", 46, None),
    )

N = SubNeoBase()

Command-line interface

You can query the data using:

python -m neobase PAR NCE

Tests

tox

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neobase-0.33.22.tar.gz (4.0 MB view details)

Uploaded Source

Built Distribution

NeoBase-0.33.22-py3-none-any.whl (4.0 MB view details)

Uploaded Python 3

File details

Details for the file neobase-0.33.22.tar.gz.

File metadata

  • Download URL: neobase-0.33.22.tar.gz
  • Upload date:
  • Size: 4.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for neobase-0.33.22.tar.gz
Algorithm Hash digest
SHA256 d7874792184aeaa0f6e5c7d831edb1e3da9265eea2fccbea5dc69e7c43a16fc8
MD5 a2dbde3018db902e715125d6481ce264
BLAKE2b-256 25e8226a5aecead67bf5d7ca5f1feb2880cd009081408db336eddfdd28e3530c

See more details on using hashes here.

Provenance

The following attestation bundles were made for neobase-0.33.22.tar.gz:

Publisher: python-package.yml on alexprengere/neobase

Attestations:

File details

Details for the file NeoBase-0.33.22-py3-none-any.whl.

File metadata

  • Download URL: NeoBase-0.33.22-py3-none-any.whl
  • Upload date:
  • Size: 4.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for NeoBase-0.33.22-py3-none-any.whl
Algorithm Hash digest
SHA256 94d548f5378e1d338055d11871a50375ca48b06bcac1a5e9c124604523ea1cc9
MD5 f81cf004378a61d44ffa1bf3a8582b0b
BLAKE2b-256 b8b123096ac6389c5965e1692e02eea310d6e87b29842cb27b7dce6522f76f4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for NeoBase-0.33.22-py3-none-any.whl:

Publisher: python-package.yml on alexprengere/neobase

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page