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.3+. 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='[YOUR_CLIENT_ID]',
    client_secret='[YOUR_CLIENT_SECRET]'
)

try:
    response = amadeus.reference_data.urls.checkin_links.get(airline='1X')
    print(response.data)
    # => [{'type': 'checkin-link', 'id': '1XEN-GBWeb', 'href': 'https://www....
except ResponseError as error:
    print(error)

Initialization

The client can be initialized directly.

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

Alternatively it can be initialized without any paramters 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?airline=1X would be:

amadeus.reference_data.urls.checkin_links.get(airline='1X')

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

For example, GET /v1/shopping/hotels/123/hotel-offers would be:

amadeus.hotel(123).hotel_offers.get(...)

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

amadeus.get('/v2/reference-data/urls/checkin-links', airline='1X')

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 avaulable as the .body attribute.

from amadeus import Location

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

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

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='...',
    client_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='...',
    client_secret='...',
    log_level='debug'
)

List of supported endpoints

# Airpot and City Search
# Find all the cities and airportes 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()

# Aiport Nearest Relevant Airport
amadeus.reference_data.locations.airports.get(longitude=49.000, latitude=2.55)

# Flight Cheapest Date Search
amadeus.shopping.flight_dates.get(origin='NCE', destination='PAR', duration=1)

# Flight Checkin Links
amadeus.reference_data.urls.checkin_links.get(airline='LH')

# Airline Code Lookup
amadeus.reference_data.airlines.get(IATACode='BA')

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

# Flight Low-fare Search
amadeus.shopping.flight_offers.get(origin='MAD', destination='OPO', "2017-04-20')

# Flight Most Searched Destinations
amadeus.travel.analytics.fare_searches.get(origin='NCE', sourceCountry='FR', period='2017-08')

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

# Flight Most Traveled Destinations
amadeus.travel.analytics.air_traffic.traveled.get(origin='NCE', period='2017-08')

# Flight Busiest Travel Period
amadeus.travel.analytics.air_traffic.busiest_period.get(origin='NCE', period='2017-08')

# Hotel Search API
# List of Hotels by City Code
amadeus.shopping.hotel_offers.get(cityCode = 'PAR')
# Get list of offers for a specific Hotel
amadeus.shopping.hotel('SMPARCOL').hotel_offers.get()
# Confirm the availability of a specific offer for a specific Hotel
amadeus.shopping.hotel('SMPARCOL').offer('4BA070BA10485322FA2C7E78C7852E').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.

Filename, size & hash SHA256 hash help File type Python version Upload date
amadeus-1.1.0-py2.py3-none-any.whl (35.1 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Aug 1, 2018
amadeus-1.1.0.tar.gz (18.5 kB) Copy SHA256 hash SHA256 Source None Aug 1, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page