Amadeus Travel API的Python模块

amadeus的Python项目详细描述


Module VersionBuild StatusMaintainabilityDependenciesContact Support

Amadeus为旅游业提供了一套API。航班,酒店, 地点等等。

有关更多详细信息,请参见github上的Amadeus for Developers Portalclass reference

安装

此sdk需要python 2.7+或3.4+。你可以直接用pip安装它。

pip install amadeus

您还可以将其添加到requirements.txt文件中,并使用以下命令安装:

pip install -r requirements.txt

开始

要进行第一次api调用,您需要register for an Amadeus Developer Account并设置第一次 申请。

fromamadeusimportClient,ResponseErroramadeus=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)exceptResponseErroraserror:print(error)

初始化

客户端可以直接初始化。

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

或者,如果 环境变量AMADEUS_CLIENT_IDAMADEUS_CLIENT_SECRET存在。

amadeus=Client()

您的凭据可以在Amadeus dashboard上找到。Sign up为今天的帐户。

默认情况下,sdk的环境是test环境。到 切换到生产(付费)环境请切换主机名 如下所示:

amadeus=Client(hostname='production')

文档

Amadeus有大量的API,我们的文档将为您提供 从今天开始。去我们的Reference 有关每个sdk方法及其参数的深入信息的文档 和返回类型。

进行API调用

这个库方便地将每个api路径映射到类似的路径。

例如,GET /v2/reference-data/urls/checkin-links?airlineCode=BA 将是:

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

类似地,要按id选择资源,可以将id传递给 奇异路径。

例如,GET /v2/shopping/hotel-offers/XZY将是:

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

也可以直接使用^{tt6}进行任意api调用。$ 方法:

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

响应

每个api调用都返回一个Response对象。如果包含的api调用 json响应它将json解析为.result属性。 如果此数据还包含一个data键,它将使该键可用 作为.data属性。反应的原始主体总是 可用作.body属性。

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

日志记录和调试

sdk使添加自己的记录器变得容易。

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)

另外,要启用更详细的日志记录,可以设置 在您自己的记录器上设置适当的级别,尽管最简单的方法是 在初始化时通过参数启用调试,或使用 AMADEUS_LOG_LEVEL环境变量。

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

支持的终结点列表

# Flight Inspiration Searchamadeus.shopping.flight_destinations.get(origin='MAD')# Flight Cheapest Date Searchamadeus.shopping.flight_dates.get(origin='MAD',destination='MUC')# Flight Low-fare Searchamadeus.shopping.flight_offers.get(origin='MAD',destination='NYC',departureDate='2019-08-01')# 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()# 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 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# Get list of Hotels by city codeamadeus.shopping.hotel_offers.get(cityCode='LON')# Get list of offers for a specific hotelamadeus.shopping.hotel_offers_by_hotel.get(hotelId='IALONCHO')# Confirm the availability of a specific offeramadeus.shopping.hotel_offer('D5BEE9D0D08B6678C2F5FAD910DC110BCDA187D21D4FCE68ED423426D0A246BB').get()# Point of Interest# What are the popular places in Barcelona (based a geo location and a radius)amadeus.reference_data.locations.points_of_interest.get(latitude=41.397158,longitude=2.160873)# What are the popular places in Barcelona? (based on a square)amadeus.reference_data.locations.points_of_interest.by_square.get(north=41.397158,west=2.160873,south=41.394582,east=2.177181)

开发和贡献

想做贡献吗?请阅读我们的Contributors Guide以获取有关安装和 在开发环境中运行此代码。

许可证

这个库是在MIT License下发布的。

帮助

我们的developer support team在这里 帮助你。你可以在StackOverflowemail找到我们。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java Hibernate@ManyToMany mapping只在一个方向上在数据库中添加记录   java将文件上载到tomcat服务器外部的文件夹   java将摄像头捕获的图像上传到服务器   java如何创建Rest API并为进程添加时间延迟?   springmodulesvalidation0中缺少java注释包。8a源文件   如何在java中打印SOAP头   Spring security中的java自定义消息,包括UserDetailsService实现和异常   java如何使用Htmlunit中的表单数据登录站点   web如何在WildFly上自动运行java文件   java如何从已经使用另一个方法传递的参数的方法中获取返回值?   java我在JFrame上有一个索引越界。setContentPane   java中的循环序列/系列打印   java maven 3 webapp没有要运行的测试吗?   java CORS不允许POST请求   java再次在派生类中的Jackson中添加字段,该字段在基类中被忽略   爪哇坑测试显示仆从由于超时而异常退出   java寻找第10001个素数   java jboss是否更改web应用程序上下文根?