Skip to main content

Trip Ninja SDK

Project description

Trip Ninja SDK

The Trip Ninja Python SDK is used for interacting with the Trip Ninja API through a easy-to-use library and suite of tools.

Installing

Python 3.10 or higher is required

Linux/MacOS

python3 -m pip install -U tn_sdk

Windows

py -3 -m pip install -U tn_sdk

Quick Example

import json
import tn_sdk
# Client ID and Client Secret can be retrieved from the Admin Panel
tn_client = tn_sdk.TnApi(
    client_id="...", # Can be set via TN_SDK_CLIENT_ID env variable
    client_secret="...", # Can be set via TN_SDK_CLIENT_SECRET env variable
)
request_data = {
    "trip_id": "",
    "datasource_responses": {
        "4b69b995e699534c1c644381b760c990795efff9": [
            {
                "pricing_solution_id": "e494c1f1d172380259a61b05990d61cbb68b35a9",
                "total_price": 392.22,
                "segment_source": "travelport",
                "is_private_fare": False,
                "refundable": False,
                "segments": [
                    [
                        {
                            "departure_time": "2025-11-15T16:40:00.000-04:00",
                            "departure_timestamp": 1763239200,
                            "arrival_time": "2025-11-15T17:35:00.000-05:00",
                            "arrival_timestamp": 1763246100,
                            "flight_number": "667",
                            "operating_carrier": "AC",
                            "transportation_type": "flight",
                            "fare_type": "PublicFare",
                            "cabin_class": "E",
                            "from_iata": "YHZ",
                            "to_iata": "YUL"
                        },
                        {
                            "departure_time": "2025-11-15T18:20:00.000-05:00",
                            "departure_timestamp": 1763248800,
                            "arrival_time": "2025-11-15T20:50:00.000-08:00",
                            "arrival_timestamp": 1763268600,
                            "flight_number": "311",
                            "operating_carrier": "AC",
                            "transportation_type": "flight",
                            "fare_type": "PublicFare",
                            "cabin_class": "E",
                            "from_iata": "YUL",
                            "to_iata": "YVR"
                        }
                    ]
                ],
                "baggage": None
            },
        ],
    }
}
request_data_json = json.dumps(request_data)
# JSON encoded string representing the request data
compressed_data = tn_client.prepare_data_for_generate_solutions(request_data_json)
# Compresses the data and returns the compressed_data

Responses

# Compressed Data 
eJztlEGL2zAQhe/7K4zPm0WSLdnSrZSWHnoopS20ZTEjW3KcKLaR5C1lyX8vclJnw7pxw9JbBbpI8968EZ/9eBNFURR72/RFU8UiisFVetxbs3HrSm83sDY/tnrjDFQaNmAqp+Pbg64CD64bbKkKq1zftU65WESP4+1YkUrGJedUMc5pkpa4ZGma5FhmDJWco4xTpbXmsYi+T6qwTh6TV2+bsmnrwnVm8E3XHhOrlKcl1rjCGUlyRCgHhiWinKOK4VJKlsuEAj+GPrP0nQdTBGMViyjh5I6QmTKn6p1qfXGYNTT1Fh6U6Tvr52wbFzwfwKtCgw0CDcapmUqr9NBWIM2lomN79+yRfq/50/lnPHOuVA/WD1YVvtmNgxFE6ArjFaafMBMpEgjdIYRWKBUIzcx6wc552PWxiHDGEpJwgtCCHGx4NDObJRMJnbLQv8jy1OwsScrwYhJtmnrti3bYSWVDFMaypYZdryz4AGgZeh90r14vybyF1gWQYGTa/+zH2Q8JlsSBrknyYZCmKd8G4BZkJcimLUoDLjAVv1lsY7td0YCHUP313bfFmbpT9ef38R+L97f/BtxcEHQVLBfATfP8JeASJOgpS/4ScFnOrgc3wfg/uH5C8Qpwv3y8AO7szf2z0/uZv7mEuoY6DN4OxpzdP/kejsr9zf4XgRWmhw==

Unsuccessful Response

InvalidDataException: [INVALID_DATA] Input must be a JSON-encoded string

Development

Setup

From an active virtual env, cd into the directory

pip install -e .

-e installs it in editable mode. Meaning it will update as you modify the source code without having to re-run the installation command.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tn_sdk-0.0.4.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tn_sdk-0.0.4-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file tn_sdk-0.0.4.tar.gz.

File metadata

  • Download URL: tn_sdk-0.0.4.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for tn_sdk-0.0.4.tar.gz
Algorithm Hash digest
SHA256 e26e6de6a9e1a6f3e6167eccc5cd149f1133ab860f898b3ec08f1e358b0645f7
MD5 356f5c6d11a0037ac534e48410871d56
BLAKE2b-256 8153bade99a305beab88a830b49949ec6f81bee4c75e94f5e19760648edee858

See more details on using hashes here.

Provenance

The following attestation bundles were made for tn_sdk-0.0.4.tar.gz:

Publisher: publish.yml on trip-ninja-inc/tn-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tn_sdk-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: tn_sdk-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for tn_sdk-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 715a02bbfb393d29c82271cea92cd29fd7944d3325b0fc3c444c66d2e806adb5
MD5 369e255a68e8aed31a610c97fc842b0d
BLAKE2b-256 a27d997b18988c3c27fd999182d0f029b2125800c5aaa383c3e26a596483c030

See more details on using hashes here.

Provenance

The following attestation bundles were made for tn_sdk-0.0.4-py3-none-any.whl:

Publisher: publish.yml on trip-ninja-inc/tn-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page