Skip to main content

Python module for the Amadeus travel APIs

Project description

Module Version Build Status Maintainability Dependencies Contact Support

Amadeus provides a set of APIs for the travel industry. Flights, Hotels, Locations and more.

For more details see the Amadeus for Developers Portal and the class reference here on GitHub.

Installation

This SDK requires Python 2.7+ or 3.4+. You can install it directly with pip.

pip install amadeus

You can also add it to your requirements.txt file and install using:

pip install -r requirements.txt

Getting Started

To make your first API call you will need to register for an Amadeus Developer Account and set up your first application.

from amadeus import Client, ResponseError

amadeus = Client(
    client_id='REPLACE_BY_YOUR_API_KEY',
    client_secret='REPLACE_BY_YOUR_API_SECRET'
)

try:
    response = amadeus.reference_data.urls.checkin_links.get(airlineCode='BA')
    print(response.data)
except ResponseError as error:
    print(error)

Initialization

The client can be initialized directly.

# Initialize using parameters
amadeus = Client(client_id='REPLACE_BY_YOUR_API_KEY', client_secret='REPLACE_BY_YOUR_API_SECRET')

Alternatively it can be initialized without any parameters if the environment variables AMADEUS_CLIENT_ID and AMADEUS_CLIENT_SECRET are present.

amadeus = Client()

Your credentials can be found on the Amadeus dashboard. Sign up for an account today.

By default the environment for the SDK is the test environment. To switch to a production (paid-for) environment please switch the hostname as follows:

amadeus = Client(hostname='production')

Documentation

Amadeus has a large set of APIs, and our documentation is here to get you started today. Head over to our Reference documentation for in-depth information about every SDK method, its arguments and return types.

Making API calls

This library conveniently maps every API path to a similar path.

For example, GET /v2/reference-data/urls/checkin-links?airlineCode=BA would be:

amadeus.reference_data.urls.checkin_links.get(airlineCode='BA')

Similarly, to select a resource by ID, you can pass in the ID to the singular path.

For example, GET /v2/shopping/hotel-offers/XZY would be:

amadeus.shopping.hotel_offer('4BA070CE929E135B3268A9F2D0C51E9D4A6CF318BA10485322FA2C7E78C7852E').get()

You can make any arbitrary API call as well directly with the .get method:

amadeus.get('/v2/reference-data/urls/checkin-links', airlineCode='BA')

Response

Every API call returns a Response object. If the API call contained a JSON response it will parse the JSON into the .result attribute. If this data also contains a data key, it will make that available as the .data attribute. The raw body of the response is always available as the .body attribute.

from amadeus import Location

response = amadeus.reference_data.locations.get(
    keyword='LON',
    subType=Location.ANY
)

print(response.body) #=> The raw response, as a string
print(response.result) #=> The body parsed as JSON, if the result was parsable
print(response.data) #=> The list of locations, extracted from the JSON

Pagination

If an API endpoint supports pagination, the other pages are available under the .next, .previous, .last and .first methods.

from amadeus import Location

response = amadeus.reference_data.locations.get(
    keyword='LON',
    subType=Location.ANY
)

amadeus.next(response) #=> returns a new response for the next page

If a page is not available, the method will return None.

Logging & Debugging

The SDK makes it easy to add your own logger.

import logging

logger = logging.getLogger('your_logger')
logger.setLevel(logging.DEBUG)

amadeus = Client(
    client_id='REPLACE_BY_YOUR_API_KEY',
    client_secret='REPLACE_BY_YOUR_API_SECRET',
    logger=logger
)

Additionally, to enable more verbose logging, you can set the appropriate level on your own logger, though the easiest way would be to enable debugging via a parameter on initialization, or using the AMADEUS_LOG_LEVEL environment variable.

amadeus = Client(
    client_id='REPLACE_BY_YOUR_API_KEY',
    client_secret='REPLACE_BY_YOUR_API_SECRET',
    log_level='debug'
)

List of supported endpoints

# Flight Inspiration Search
amadeus.shopping.flight_destinations.get(origin='MAD')

# Flight Cheapest Date Search
amadeus.shopping.flight_dates.get(origin='NYC', destination='MAD')

# Flight Low-fare Search
amadeus.shopping.flight_offers.get(origin='MAD', destination='NYC', departureDate='2019-08-01')

# Flight Checkin Links
amadeus.reference_data.urls.checkin_links.get(airlineCode='BA')

# Airline Code Lookup
amadeus.reference_data.airlines.get(airlineCodes='U2')

# Airport and City Search (autocomplete)
# Find all the cities and airports starting by 'LON'
amadeus.reference_data.locations.get(keyword='LON', subType=Location.ANY)
# Get a specific city or airport based on its id
amadeus.reference_data.location('ALHR').get()

# Airport Nearest Relevant Airport (for London)
amadeus.reference_data.locations.airports.get(longitude=0.1278, latitude=51.5074)

# Flight Most Searched Destinations
# Which were the most searched flight destinations from Madrid in August 2017?
amadeus.travel.analytics.air_traffic.searched.get(originCityCode='MAD', marketCountryCode='ES', searchPeriod='2017-08')
# How many people in Spain searched for a trip from Madrid to New-York in September 2017?
amadeus.travel.analytics.air_traffic.searched_by_destination.get(originCityCode='MAD', destinationCityCode='NYC', marketCountryCode='ES', searchPeriod='2017-08')

# Flight Most Booked Destinations
amadeus.travel.analytics.air_traffic.booked.get(originCityCode='MAD', period='2017-08')

# Flight Most Traveled Destinations
amadeus.travel.analytics.air_traffic.traveled.get(originCityCode='MAD', period='2017-01')

# Flight Busiest Travel Period
amadeus.travel.analytics.air_traffic.busiest_period.get(cityCode='MAD', period='2017', direction='ARRIVING')

# Hotel Search
# Get list of Hotels by city code
amadeus.shopping.hotel_offers.get(cityCode = 'LON')
# Get list of offers for a specific hotel
amadeus.shopping.hotel_offers_by_hotel.get(hotelId = 'IALONCHO')
# Confirm the availability of a specific offer
amadeus.shopping.hotel_offer('D5BEE9D0D08B6678C2F5FAD910DC110BCDA187D21D4FCE68ED423426D0A246BB').get()

Development & Contributing

Want to contribute? Read our Contributors Guide for guidance on installing and running this code in a development environment.

License

This library is released under the MIT License.

Help

Our developer support team is here to help you. You can find us on StackOverflow, and email.

Project details


Download files

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

Source Distribution

amadeus-3.0.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

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

amadeus-3.0.0-py2.py3-none-any.whl (36.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file amadeus-3.0.0.tar.gz.

File metadata

  • Download URL: amadeus-3.0.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.3

File hashes

Hashes for amadeus-3.0.0.tar.gz
Algorithm Hash digest
SHA256 6b7ff07b5b272865ac3680e047efff0ca553dbd19c27ffcaf209bb1968e6a789
MD5 060735aa5027c36971b4a7aae28010b2
BLAKE2b-256 7e3618361a2efe695efe1092a43bd113715bb507147e56036704e9ded9f21b83

See more details on using hashes here.

File details

Details for the file amadeus-3.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: amadeus-3.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 36.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.3

File hashes

Hashes for amadeus-3.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 066270b9070f3b92820f4245212ce01aaf32083cb558252ee72ad8190250f067
MD5 1bdf2230954e477ea56baf7caa22f5d0
BLAKE2b-256 73e6cbf06c23426ce6132646d9764c0078cf22789cd27e9c7db9a7a2e4105afa

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