Skip to main content

Python library to manipulate Open Travel Data

Project description

Minimalist GeoBases implementation:

  • no dependencies

  • compatible with Python 2.6+, Python 3.x, 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

You can install directly after cloning:

pip install --user .

Or use the Python package:

pip install --user neobase

Doc

Check out readthedocs for the API.

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),
    )

    # Drop duplicates, keep only the first POR with a specific key
    # Default value is True
    DUPLICATES = False

N = SubNeoBase()

You can also 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")

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.26.1.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

NeoBase-0.26.1-py2.py3-none-any.whl (3.4 MB view details)

Uploaded Python 2Python 3

File details

Details for the file NeoBase-0.26.1.tar.gz.

File metadata

  • Download URL: NeoBase-0.26.1.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for NeoBase-0.26.1.tar.gz
Algorithm Hash digest
SHA256 5a28b999734aef7240baee3cf81e63024430b07b539d52bdc77b6cbfefe39b34
MD5 0bcb75eb179211bc225f11a9214885ee
BLAKE2b-256 423d9eb94508216cd5b9a5c97dfa7a515948b7f5a2df4d15e05d3506a9fdc362

See more details on using hashes here.

File details

Details for the file NeoBase-0.26.1-py2.py3-none-any.whl.

File metadata

  • Download URL: NeoBase-0.26.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for NeoBase-0.26.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cc6e9a356adddf4e74b0c7fac27042b4a516b7b3dd4ad6098f6ccac533b236e0
MD5 1fed099357af9f66feb55892a9a8a3bf
BLAKE2b-256 e6e696007afdc827f5050a1bd148a4e10b4b4292fdc3817f12ac466e2afb58f9

See more details on using hashes here.

Supported by

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