Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python library for the Amadeus Self-Service travel APIs

License

NotificationsYou must be signed in to change notification settings

amadeus4dev/amadeus-python

Repository files navigation

Module VersionBuild StatusMaintainabilityDependenciesDiscord

Amadeus provides a rich set of APIs for the travel industry. For more details, check out theAmadeus for Developers Portal or theSDK class reference.

Installation

This SDK requires Python 3.8+. You can install it directly with pip:

pip install amadeus

OR, 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 toregister for an Amadeus Developer Account andset up your firstapplication.

fromamadeusimportClient,ResponseErroramadeus=Client(client_id='REPLACE_BY_YOUR_API_KEY',client_secret='REPLACE_BY_YOUR_API_SECRET')try:response=amadeus.shopping.flight_offers_search.get(originLocationCode='MAD',destinationLocationCode='ATH',departureDate='2024-11-01',adults=1)print(response.data)exceptResponseErroraserror:print(error)

Examples

You can find all the endpoints in self-containedcode examples.

Initialization

The client can be initialized directly.

# Initialize using parametersamadeus=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 variablesAMADEUS_CLIENT_ID andAMADEUS_CLIENT_SECRET are present.

amadeus=Client()

Your credentials can be found on theAmadeus dashboard.

By default, the SDK environment is set totest environment. To switch to a production (pay-as-you-go) 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 ourreference documentation for in-depth information about every SDK method, as well as 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('XYZ').get()

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

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

Or, withPOST method:

amadeus.post('/v1/shopping/flight-offers/pricing',body)

Response

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

fromamadeusimportLocationresponse=amadeus.reference_data.locations.get(keyword='LON',subType=Location.ANY)print(response.body)#=> The raw response, as a stringprint(response.result)#=> The body parsed as JSON, if the result was parsableprint(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.

fromamadeusimportLocationresponse=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 returnNone.

Logging & Debugging

The SDK makes it easy to add your own logger.

importlogginglogger=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. The easiest way would be to enable debugging via a parameter during initialization, or using theAMADEUS_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 Searchamadeus.shopping.flight_destinations.get(origin='MAD')# Flight Cheapest Date Searchamadeus.shopping.flight_dates.get(origin='MAD',destination='MUC')# Flight Offers Search GETamadeus.shopping.flight_offers_search.get(originLocationCode='SYD',destinationLocationCode='BKK',departureDate='2022-11-01',adults=1)# Flight Offers Search POSTamadeus.shopping.flight_offers_search.post(body)# Flight Offers Priceflights=amadeus.shopping.flight_offers_search.get(originLocationCode='SYD',destinationLocationCode='BKK',departureDate='2022-11-01',adults=1).dataamadeus.shopping.flight_offers.pricing.post(flights[0])amadeus.shopping.flight_offers.pricing.post(flights[0:2],include='credit-card-fees,other-services')# Flight Create Ordersamadeus.booking.flight_orders.post(flights[0],traveler)# Flight Order Management# The flight ID comes from the Flight Create Orders (in test environment it's temporary)# Retrieve the order based on it's IDflight_booking=amadeus.booking.flight_orders.post(body).dataamadeus.booking.flight_order(flight_booking['id']).get()# Delete the order based on it's IDamadeus.booking.flight_order(flight_booking['id']).delete()# Flight SeatMap Display GETamadeus.shopping.seatmaps.get(**{"flight-orderId":"orderid"})# Flight SeatMap Display POSTamadeus.shopping.seatmaps.post(body)# Flight Availabilities POSTamadeus.shopping.availability.flight_availabilities.post(body)# Branded Fares Upsellamadeus.shopping.flight_offers.upselling.post(body)# Flight Choice Predictionbody=amadeus.shopping.flight_offers_search.get(originLocationCode='MAD',destinationLocationCode='NYC',departureDate='2022-11-01',adults=1).resultamadeus.shopping.flight_offers.prediction.post(body)# Flight Checkin Linksamadeus.reference_data.urls.checkin_links.get(airlineCode='BA')# Airline Code Lookupamadeus.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 idamadeus.reference_data.location('ALHR').get()# City Searchamadeus.reference_data.locations.cities.get(keyword='PAR')# Airport Nearest Relevant Airport (for London)amadeus.reference_data.locations.airports.get(longitude=0.1278,latitude=51.5074)# Flight Most Booked Destinationsamadeus.travel.analytics.air_traffic.booked.get(originCityCode='MAD',period='2017-08')# Flight Most Traveled Destinationsamadeus.travel.analytics.air_traffic.traveled.get(originCityCode='MAD',period='2017-01')# Flight Busiest Travel Periodamadeus.travel.analytics.air_traffic.busiest_period.get(cityCode='MAD',period='2017',direction='ARRIVING')# Hotel Search v3# Get list of available offers by hotel idsamadeus.shopping.hotel_offers_search.get(hotelIds='RTPAR001',adults='2')# Check conditions of a specific offeramadeus.shopping.hotel_offer_search('XXX').get()# Hotel List# Get list of hotels by hotel idamadeus.reference_data.locations.hotels.by_hotels.get(hotelIds='ADPAR001')# Get list of hotels by city codeamadeus.reference_data.locations.hotels.by_city.get(cityCode='PAR')# Get list of hotels by a geocodeamadeus.reference_data.locations.hotels.by_geocode.get(longitude=2.160873,latitude=41.397158)# Hotel Name Autocompleteamadeus.reference_data.locations.hotel.get(keyword='PARI',subType=[Hotel.HOTEL_GDS,Hotel.HOTEL_LEISURE])# Hotel Booking v2# The offerId comes from the hotel_offer aboveamadeus.booking.hotel_orders.post(guests=guests,travel_agent=travel_agent,room_associations=room_associations,payment=payment)# Hotel Booking v1# The offerId comes from the hotel_offer aboveamadeus.booking.hotel_bookings.post(offerId,guests,payments)# Hotel Ratings# What travelers think about this hotel?amadeus.e_reputation.hotel_sentiments.get(hotelIds='ADNYCCTB')# Trip Purpose Predictionamadeus.travel.predictions.trip_purpose.get(originLocationCode='ATH',destinationLocationCode='MAD',departureDate='2022-11-01',returnDate='2022-11-08')# Flight Delay Predictionamadeus.travel.predictions.flight_delay.get(originLocationCode='NCE',destinationLocationCode='IST',departureDate='2022-08-01', \departureTime='18:20:00',arrivalDate='2022-08-01',arrivalTime='22:15:00',aircraftCode='321',carrierCode='TK',flightNumber='1816',duration='PT31H10M')# Airport On-Time Performanceamadeus.airport.predictions.on_time.get(airportCode='JFK',date='2022-11-01')# Airport Routesamadeus.airport.direct_destinations.get(departureAirportCode='BLR')# Travel Recommendationsamadeus.reference_data.recommended_locations.get(cityCodes='PAR',travelerCountryCode='FR')# Retrieve status of a given flightamadeus.schedule.flights.get(carrierCode='AZ',flightNumber='319',scheduledDepartureDate='2022-09-13')# Tours and Activities# What are the popular activities in Madrid (based a geo location and a radius)amadeus.shopping.activities.get(latitude=40.41436995,longitude=-3.69170868)# What are the popular activities in Barcelona? (based on a square)amadeus.shopping.activities.by_square.get(north=41.397158,west=2.160873,south=41.394582,east=2.177181)# Returns a single activity from a given idamadeus.shopping.activity('4615').get()# Returns itinerary price metricsamadeus.analytics.itinerary_price_metrics.get(originIataCode='MAD',destinationIataCode='CDG',departureDate='2021-03-21')# Airline Routesamadeus.airline.destinations.get(airlineCode='BA')# Transfer Searchamadeus.shopping.transfer_offers.post(body)# Transfer Bookingamadeus.ordering.transfer_orders.post(body,offerId='1000000000')# Transfer Managementamadeus.ordering.transfer_order('ABC').transfers.cancellation.post(body,confirmNbr=123)

Development & Contributing

Want to contribute? Read ourContributorsGuide for guidance on installing andrunning this code in a development environment.

License

This library is released under theMIT License.

Help

You can find us onStackOverflow or join our developer community onDiscord.


[8]ページ先頭

©2009-2025 Movatter.jp