{"id":15581418,"url":"https://github.com/alexprengere/neobase","last_synced_at":"2025-03-16T19:32:20.669Z","repository":{"id":46099911,"uuid":"46869843","full_name":"alexprengere/neobase","owner":"alexprengere","description":"Minimalist GeoBases: single file, no dependency, compatible with Python 2.6+, Python 3.x, Pypy","archived":false,"fork":false,"pushed_at":"2024-05-28T09:19:48.000Z","size":75004,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-29T00:37:25.123Z","etag":null,"topics":["geography","map","python","web"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexprengere.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-25T15:24:44.000Z","updated_at":"2024-06-05T11:43:02.303Z","dependencies_parsed_at":"2023-12-14T11:59:10.281Z","dependency_job_id":"64c80bbb-64ea-4163-a7bf-3e2a1ca14ed7","html_url":"https://github.com/alexprengere/neobase","commit_stats":{"total_commits":863,"total_committers":2,"mean_commits":431.5,"dds":0.006952491309385911,"last_synced_commit":"918693023c57e5fc07d2a0e2728f0c6953b3993e"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2Fneobase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2Fneobase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2Fneobase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2Fneobase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexprengere","download_url":"https://codeload.github.com/alexprengere/neobase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826797,"owners_count":20354221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geography","map","python","web"],"created_at":"2024-10-02T19:46:42.697Z","updated_at":"2025-03-16T19:32:20.661Z","avatar_url":"https://github.com/alexprengere.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"NeoBase |actions|_ |cratev|_ |crated|_\n======================================\n\n.. _actions : https://github.com/alexprengere/neobase/actions/workflows/python-package.yml\n.. |actions| image:: https://github.com/alexprengere/neobase/actions/workflows/python-package.yml/badge.svg\n\n.. _cratev : https://pypi.org/project/NeoBase/\n.. |cratev| image:: https://img.shields.io/pypi/v/neobase.svg\n\n.. _crated : https://pypi.org/project/NeoBase/\n.. |crated| image:: https://static.pepy.tech/badge/neobase\n\nMinimalist `GeoBases \u003chttps://github.com/opentraveldata/geobases/\u003e`__\nimplementation:\n\n-  no dependencies\n-  compatible with Python 3.9+, CPython and PyPy\n-  one data source:\n   `opentraveldata \u003chttps://github.com/opentraveldata/opentraveldata\u003e`__\n-  one Python module for easier distribution on clusters (like Hadoop)\n-  faster load time (5x)\n-  tested with pytest and tox\n\n.. code:: python\n\n    \u003e\u003e\u003e from neobase import NeoBase\n    \u003e\u003e\u003e b = NeoBase()\n    \u003e\u003e\u003e b.get('ORY', 'city_code_list')\n    ['PAR']\n    \u003e\u003e\u003e b.get('ORY', 'city_name_list')\n    ['Paris']\n    \u003e\u003e\u003e b.get('ORY', 'country_code')\n    'FR'\n    \u003e\u003e\u003e b.distance('ORY', 'CDG')\n    34.87...\n    \u003e\u003e\u003e b.get_location('ORY')\n    LatLng(lat=48.72..., lng=2.35...)\n\nInstallation\n------------\n\nUse the Python package:\n\n.. code:: bash\n\n    pip install neobase\n\nDocs\n----\n\nCheck out `readthedocs \u003chttp://neobase.readthedocs.org/en/latest/\u003e`__ for the API.\n\nYou can customize the source data when initializing:\n\n.. code:: python\n\n    with open(\"file.csv\") as f:\n        N = NeoBase(f)\n\nOtherwise 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.\n\nYou can manually retrieve the latest data source yourself too, but you expose yourself to some breaking changes if they occur in the data.\n\n.. code:: python\n\n    from io import StringIO\n    from urllib.request import urlopen\n\n    from neobase import NeoBase, OPTD_POR_URL\n\n    data = urlopen(OPTD_POR_URL).read().decode('utf8')\n    N = NeoBase(StringIO(data))\n    N.get(\"PAR\")\n\nThe reference date of validity can be changed as well:\n\n.. code:: python\n\n    N = NeoBase(date=\"2000-01-01\")\n    N.get(\"AIY\")  # was decommissioned in 2015\n\nBy 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.\n\nYou 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\n.. code:: python\n\n    N = NeoBase(duplicates=False)\n    len(N)  # about 10,000 \"only\"\n\nNote that you can use the ``OPTD_POR_DUPLICATES`` environment variable to control this as well: set it to ``0`` to drop duplicates.\n\nFinally, you can customize fields loaded by subclassing.\n\n.. code:: python\n\n    class SubNeoBase(NeoBase):\n        KEY = 0  # iata_code\n\n        # Those loaded fields are the default ones\n        FIELDS = (\n            (\"name\", 6, None),\n            (\"lat\", 8, None),\n            (\"lng\", 9, None),\n            (\"page_rank\", 12, lambda s: float(s) if s else None),\n            (\"country_code\", 16, None),\n            (\"country_name\", 18, None),\n            ('continent_name', 19, None),\n            (\"timezone\", 31, None),\n            (\"city_code_list\", 36, lambda s: s.split(\",\")),\n            ('city_name_list', 37, lambda s: s.split('=')),\n            ('location_type', 41, None),\n            (\"currency\", 46, None),\n        )\n\n    N = SubNeoBase()\n\nCommand-line interface\n----------------------\n\nYou can query the data using:\n\n.. code:: bash\n\n    python -m neobase PAR NCE\n\nTests\n-----\n\n.. code:: bash\n\n    tox\n\nA note about performance\n------------------------\n\nThe geographical operations like ``N.find_near(\"ORY\", 100)`` or ``N.find_closest_from(\"ORY\")`` perform a full scan of the data, and are not optimized (remember that this library has no dependencies by design).\n\nIf you want a more efficient solution, you should use a spatial index like a *BallTree*, for example using `scikit-learn \u003chttps://scikit-learn.org/stable/modules/generated/sklearn.neighbors.BallTree.html\u003e`__:\n\n.. code:: python\n\n    import numpy as np\n    from sklearn.neighbors import BallTree\n    from neobase import NeoBase\n\n    N = NeoBase()\n\n    iata_codes = []\n    coords = []\n    for key in N:\n        lat, lon = N.get_location(key)\n        if lat is not None and lon is not None:\n            iata_codes.append(N.get(key, \"iata_code\"))\n            coords.append([np.radians(lat), np.radians(lon)])\n    coords = np.array(coords)\n\n    tree = BallTree(coords, metric=\"haversine\")\n\n    def find_closest_with_balltree(coord):\n        point = np.radians(coord)\n        _, idx = tree.query([point], k=1)\n        iata_code = iata_codes[idx[0][0]]\n        return iata_code\n\n    paris = (48.8566, 2.3522)\n    print(find_closest_with_balltree(paris))  # \u003c0.1ms\n    print(list(N.find_closest_from_location(paris)))  # ~30ms\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexprengere%2Fneobase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexprengere%2Fneobase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexprengere%2Fneobase/lists"}