Giter Club home page Giter Club logo

amadeus-python's Introduction

Amadeus Python SDK

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='MAD', destination='MUC')

# 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.