airports


Nameairports JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryA comprehensive Python library for airport data management and querying heavily influenced by Tim Rogers' Airports gem. This library provides fast, efficient lookups for airport information using IATA codes, ICAO codes, cities, regions, and countries.
upload_time2024-12-15 03:29:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT License Copyright (c) [year] [fullname] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords airports aviation travel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Airports Library

A comprehensive Python library for airport data management and querying heavily influenced by [Tim Rogers' Airports gem](https://github.com/timrogers/airports). This library provides fast, efficient lookups for airport information using IATA codes, ICAO codes, cities, regions, and countries.

## Features

- Efficient lookup of airports by:
  - IATA code (e.g., "LAX")
  - ICAO code (e.g., "KLAX")
  - City name (e.g., "Los Angeles")
  - City code (e.g., "LAX")
  - Region/State (e.g., "California")
  - Region code (e.g., "US-CA")
  - Country (e.g., "United States")
  - Country code (e.g., "US")
- Fuzzy matching for city names
- Distance calculation between airports using the Haversine formula
- Lazy loading of data for optimal memory usage
- Type hints for better IDE support
- Comprehensive error handling

## Installation

```bash
pip install airports
```

## Quick Start

```python
from airports import Airports

# Initialize the library
airports = Airports()

# Look up an airport by IATA code
lax = airports.find_by_iata_code("LAX")
print(f"Found {lax['name']} in {lax['city']}, {lax['country']}")

# Find all airports in a city
nyc_airports = airports.find_all_by_city_code("NYC")
for airport in nyc_airports:
    print(f"{airport['name']} ({airport['iata']})")

# Calculate distance between airports
distance = airports.distance_between("JFK", "LAX")
print(f"Distance: {distance:.1f} km")
```

## API Reference

### Main Class: `Airports`

#### Basic Lookups

- `find_by_iata_code(iata_code: str) -> Optional[Dict]`
  - Find airport by 3-letter IATA code
  - Returns None if not found

- `find_by_icao_code(icao_code: str) -> Optional[Dict]`
  - Find airport by 4-letter ICAO code
  - Returns None if not found

#### City-based Lookups

- `find_all_by_city(city_name: str) -> List[Dict]`
  - Find all airports in a given city
  - Case-insensitive search

- `find_all_by_city_code(city_code: str) -> List[Dict]`
  - Find all airports with a specific 3-letter city code
  - Returns empty list if none found

- `fuzzy_find_city(city_name: str, cutoff: float = 0.6) -> List[Dict]`
  - Find airports in cities with names similar to input
  - Adjustable similarity threshold (cutoff)

#### Region and Country Lookups

- `find_all_by_region(region_name: str) -> List[Dict]`
  - Find all airports in a given region/state
  - Case-insensitive search

- `find_all_by_region_code(region_code: str) -> List[Dict]`
  - Find all airports by region code (e.g., "US-NY")
  - Returns empty list if none found

- `find_all_by_country(country_name: str) -> List[Dict]`
  - Find all airports in a given country
  - Case-insensitive search

- `find_all_by_country_code(country_code: str) -> List[Dict]`
  - Find all airports by 2-letter country code
  - Returns empty list if none found

#### Utility Methods

- `distance_between(airport1: Union[str, Dict], airport2: Union[str, Dict]) -> Optional[float]`
  - Calculate distance between two airports in kilometers
  - Accept either IATA codes or airport dictionaries
  - Returns None if either airport not found or missing coordinates

#### Properties

- `iata_codes: List[str]` - Get all IATA codes in dataset
- `icao_codes: List[str]` - Get all ICAO codes in dataset
- `city_codes: List[str]` - Get all city codes in dataset

### Airport Data Structure

Each airport is represented as a dictionary with the following fields:

```python
{
    # Basic Information
    "name": str,             # Full airport name
    "city": str,             # City name
    "city_code": str,        # IATA city code
    "country": str,          # Country name
    "iso_country_code": str, # ISO 3166-1 country code
    "region": str,           # Region/state name
    "iso_region_code": str,  # ISO 3166-2 region code

    # Airport Codes
    "iata": str,             # IATA airport code
    "icao": str,             # ICAO airport code

    # Location Information
    "latitude": float,       # Latitude in decimal degrees
    "longitude": float,      # Longitude in decimal degrees
    "altitude": int,         # Altitude in feet

    # Timezone Information
    "tz_name": str,          # Timezone
    "utc_offset": float,     # UTC offset
    "dst": str,              # Daylight savings region type

    # Other
    "type": str,             # Airport type
}
```

## Error Handling

The library implements robust error handling:

- Invalid IATA codes (not 3 letters) raise ValueError
- Invalid ICAO codes (not 4 letters) raise ValueError
- Invalid city codes (not 3 letters) raise ValueError
- Invalid region codes (not 4-6 characters) raise ValueError
- Invalid country codes (not 2 letters) raise ValueError

## Development

### Project Structure

```
.
├── LICENSE.txt
├── README.md
├── airports
│   ├── __init__.py
│   ├── airports.py
│   ├── data
│   │   ├── airports.json
│   │   └── incoming
│   └── merge.py
├── pyproject.toml
├── requirements-dev.txt
└── tests
    └── test_airports.py
```

### Setting Up Development Environment

1. Clone the repository:
```bash
git clone https://github.com/yourusername/airports.git
cd airports
```

2. Install development dependencies:
```bash
pip install -r requirements-dev.txt
```

3. Run tests:
```bash
pytest tests/
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.

## Acknowledgments

- Data sourced from multiple airport project databases
  - [airports - Tim Rogers](https://github.com/timrogers/airports)
  - [airports-py - Aashish Vivekanand](https://github.com/aashishvanand/airports-py)
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "airports",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "airports, aviation, travel",
    "author": null,
    "author_email": "Jeffrey Berube <berubejd@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d3/19/1815753c354c14a0f07da310a30e22ba23193a19e75949496b177a8c6c83/airports-0.1.1.tar.gz",
    "platform": null,
    "description": "# Airports Library\n\nA comprehensive Python library for airport data management and querying heavily influenced by [Tim Rogers' Airports gem](https://github.com/timrogers/airports). This library provides fast, efficient lookups for airport information using IATA codes, ICAO codes, cities, regions, and countries.\n\n## Features\n\n- Efficient lookup of airports by:\n  - IATA code (e.g., \"LAX\")\n  - ICAO code (e.g., \"KLAX\")\n  - City name (e.g., \"Los Angeles\")\n  - City code (e.g., \"LAX\")\n  - Region/State (e.g., \"California\")\n  - Region code (e.g., \"US-CA\")\n  - Country (e.g., \"United States\")\n  - Country code (e.g., \"US\")\n- Fuzzy matching for city names\n- Distance calculation between airports using the Haversine formula\n- Lazy loading of data for optimal memory usage\n- Type hints for better IDE support\n- Comprehensive error handling\n\n## Installation\n\n```bash\npip install airports\n```\n\n## Quick Start\n\n```python\nfrom airports import Airports\n\n# Initialize the library\nairports = Airports()\n\n# Look up an airport by IATA code\nlax = airports.find_by_iata_code(\"LAX\")\nprint(f\"Found {lax['name']} in {lax['city']}, {lax['country']}\")\n\n# Find all airports in a city\nnyc_airports = airports.find_all_by_city_code(\"NYC\")\nfor airport in nyc_airports:\n    print(f\"{airport['name']} ({airport['iata']})\")\n\n# Calculate distance between airports\ndistance = airports.distance_between(\"JFK\", \"LAX\")\nprint(f\"Distance: {distance:.1f} km\")\n```\n\n## API Reference\n\n### Main Class: `Airports`\n\n#### Basic Lookups\n\n- `find_by_iata_code(iata_code: str) -> Optional[Dict]`\n  - Find airport by 3-letter IATA code\n  - Returns None if not found\n\n- `find_by_icao_code(icao_code: str) -> Optional[Dict]`\n  - Find airport by 4-letter ICAO code\n  - Returns None if not found\n\n#### City-based Lookups\n\n- `find_all_by_city(city_name: str) -> List[Dict]`\n  - Find all airports in a given city\n  - Case-insensitive search\n\n- `find_all_by_city_code(city_code: str) -> List[Dict]`\n  - Find all airports with a specific 3-letter city code\n  - Returns empty list if none found\n\n- `fuzzy_find_city(city_name: str, cutoff: float = 0.6) -> List[Dict]`\n  - Find airports in cities with names similar to input\n  - Adjustable similarity threshold (cutoff)\n\n#### Region and Country Lookups\n\n- `find_all_by_region(region_name: str) -> List[Dict]`\n  - Find all airports in a given region/state\n  - Case-insensitive search\n\n- `find_all_by_region_code(region_code: str) -> List[Dict]`\n  - Find all airports by region code (e.g., \"US-NY\")\n  - Returns empty list if none found\n\n- `find_all_by_country(country_name: str) -> List[Dict]`\n  - Find all airports in a given country\n  - Case-insensitive search\n\n- `find_all_by_country_code(country_code: str) -> List[Dict]`\n  - Find all airports by 2-letter country code\n  - Returns empty list if none found\n\n#### Utility Methods\n\n- `distance_between(airport1: Union[str, Dict], airport2: Union[str, Dict]) -> Optional[float]`\n  - Calculate distance between two airports in kilometers\n  - Accept either IATA codes or airport dictionaries\n  - Returns None if either airport not found or missing coordinates\n\n#### Properties\n\n- `iata_codes: List[str]` - Get all IATA codes in dataset\n- `icao_codes: List[str]` - Get all ICAO codes in dataset\n- `city_codes: List[str]` - Get all city codes in dataset\n\n### Airport Data Structure\n\nEach airport is represented as a dictionary with the following fields:\n\n```python\n{\n    # Basic Information\n    \"name\": str,             # Full airport name\n    \"city\": str,             # City name\n    \"city_code\": str,        # IATA city code\n    \"country\": str,          # Country name\n    \"iso_country_code\": str, # ISO 3166-1 country code\n    \"region\": str,           # Region/state name\n    \"iso_region_code\": str,  # ISO 3166-2 region code\n\n    # Airport Codes\n    \"iata\": str,             # IATA airport code\n    \"icao\": str,             # ICAO airport code\n\n    # Location Information\n    \"latitude\": float,       # Latitude in decimal degrees\n    \"longitude\": float,      # Longitude in decimal degrees\n    \"altitude\": int,         # Altitude in feet\n\n    # Timezone Information\n    \"tz_name\": str,          # Timezone\n    \"utc_offset\": float,     # UTC offset\n    \"dst\": str,              # Daylight savings region type\n\n    # Other\n    \"type\": str,             # Airport type\n}\n```\n\n## Error Handling\n\nThe library implements robust error handling:\n\n- Invalid IATA codes (not 3 letters) raise ValueError\n- Invalid ICAO codes (not 4 letters) raise ValueError\n- Invalid city codes (not 3 letters) raise ValueError\n- Invalid region codes (not 4-6 characters) raise ValueError\n- Invalid country codes (not 2 letters) raise ValueError\n\n## Development\n\n### Project Structure\n\n```\n.\n\u251c\u2500\u2500 LICENSE.txt\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 airports\n\u2502   \u251c\u2500\u2500 __init__.py\n\u2502   \u251c\u2500\u2500 airports.py\n\u2502   \u251c\u2500\u2500 data\n\u2502   \u2502   \u251c\u2500\u2500 airports.json\n\u2502   \u2502   \u2514\u2500\u2500 incoming\n\u2502   \u2514\u2500\u2500 merge.py\n\u251c\u2500\u2500 pyproject.toml\n\u251c\u2500\u2500 requirements-dev.txt\n\u2514\u2500\u2500 tests\n    \u2514\u2500\u2500 test_airports.py\n```\n\n### Setting Up Development Environment\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/yourusername/airports.git\ncd airports\n```\n\n2. Install development dependencies:\n```bash\npip install -r requirements-dev.txt\n```\n\n3. Run tests:\n```bash\npytest tests/\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.\n\n## Acknowledgments\n\n- Data sourced from multiple airport project databases\n  - [airports - Tim Rogers](https://github.com/timrogers/airports)\n  - [airports-py - Aashish Vivekanand](https://github.com/aashishvanand/airports-py)",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) [year] [fullname]  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A comprehensive Python library for airport data management and querying heavily influenced by Tim Rogers' Airports gem. This library provides fast, efficient lookups for airport information using IATA codes, ICAO codes, cities, regions, and countries.",
    "version": "0.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/berubejd/airports/issues",
        "Homepage": "https://github.com/berubejd/airports",
        "Source Code": "https://github.com/berubejd/airports"
    },
    "split_keywords": [
        "airports",
        " aviation",
        " travel"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "989bac499289a9d369224d401b229f5ae13f0ba7a93aef5cf03deafc5f59f39d",
                "md5": "aaaa068eb645ea5ab870e062f995251e",
                "sha256": "0a796ccd3a18de293639fa50a56f42d4105246c6a11f6ebdf607fc0603bd9852"
            },
            "downloads": -1,
            "filename": "airports-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aaaa068eb645ea5ab870e062f995251e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 437183,
            "upload_time": "2024-12-15T03:29:39",
            "upload_time_iso_8601": "2024-12-15T03:29:39.258060Z",
            "url": "https://files.pythonhosted.org/packages/98/9b/ac499289a9d369224d401b229f5ae13f0ba7a93aef5cf03deafc5f59f39d/airports-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3191815753c354c14a0f07da310a30e22ba23193a19e75949496b177a8c6c83",
                "md5": "9a84341c8cffcf07cd83de3f48913271",
                "sha256": "53fec1d36d4a8e4bf43561eecc6d9bb986999f94cb90653b12cbd42ecb9f6e94"
            },
            "downloads": -1,
            "filename": "airports-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9a84341c8cffcf07cd83de3f48913271",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 420628,
            "upload_time": "2024-12-15T03:29:41",
            "upload_time_iso_8601": "2024-12-15T03:29:41.178497Z",
            "url": "https://files.pythonhosted.org/packages/d3/19/1815753c354c14a0f07da310a30e22ba23193a19e75949496b177a8c6c83/airports-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-15 03:29:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "berubejd",
    "github_project": "airports",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "airports"
}
        
Elapsed time: 0.41813s