A simple wrapper for connecting to TourCMS Marketplace API. This wrapper mirrors the TourCMS PHP library.
pip install tourcms
Using the library is as simple as creating a Connection object:
conn = tourcms.Connection(marketplace_id, private_key, result_type)
Your Marketplace ID and Private Key can be found in the TourCMS Partner Portal. The result type can be one of dict or raw where raw will return the raw XML from the API and dict will return a dictionary of the result. Dict requires xmltodict to be installed.
# Instantiate the connectionimportosfromtourcmsimportConnectionconn=Connection(0, os.getenv('TOURCMS_PRIVATE_KEY'))
# Check we're workingconn.api_rate_limit_status(channel_id)
=>"<?xml version="1.0" encoding="utf-8" ?><response><request>GET/api/rate_limit_status.xml</request><error>OK</error><remaining_hits>1999</remaining_hits><hourly_limit>2000</hourly_limit></response>"
# List the channels we have access toconn.list_channels(channel_id)
=>""<?xmlversion="1.0"encoding="utf-8" ?><response><request>GET/p/channels/list.xml</request><error>OK</error><channel>(...)</channel><channel>(...)</channel><channel>(...)</channel></response>"
# Show a particular channelconn.show_channel(1234567)
=>""<?xmlversion="1.0"encoding="utf-8" ?><response><request>GET/p/channels/list.xml</request><error>OK</error><channel>(...)</channel></response>"Requires xmltodict to be installed
pip install xmltodict
# Instantiate the connectionconn=Connection(0, os.getenv('TOURCMS_PRIVATE_KEY'), "dict")
# Check we're workingconn.api_rate_limit_status(channel_id)
=>OrderedDict([(u'request', u'GET /api/rate_limit_status.xml?'), (u'error', u'OK'), (u'remaining_hits', u'1999'), (u'hourly_limit', u'2000')])
obj["hourly_limit"]
=>2000Many TourCMS methods accept parameters. Most methods take a dictionary of parameters like so:
obj = conn.search_tours({"country": "GB", "lang": "en"})
- api_rate_limit_status
- list_channels
- show_channel
- search_tours
- search_hotels_range
- search_hotels_specific
- list_tours
- list_tour_images
- show_tour
- show_tour_departures
- show_tour_freesale
- show_supplier
None. xmltodict optional. Tested with Python 2.6, 2.7 & 3.3.
Copyright (c) 2012 Jonathan Harrington. See LICENSE.txt for further details.
