Code libraries for JavaScript, Python and PHP
One file each, with no dependencies. Download it, put it next to your code, and call the API with your app ID and secret.
Download
JavaScript
For Node 18 or newer, Deno and Bun.
SHA-256 7ff57a853e41afd81b9a5618c9ea2e8c2801004e5e4ac419cfa51aa73fef1153
Python
For Python 3.8 or newer. Standard library only.
SHA-256 e30db2137a48539828f50806a28c0e7adad07b473a9ea102161770cb48b191fa
PHP
For PHP 7.4 or newer with the curl extension.
SHA-256 bcb316772ec363614ca21130b02ea2b00051d42e006fea34674a4748ab5afbf2
Tested on Node 26, Python 3.14 and PHP 8.4.
How to use it
- Put the file in your project.
- Create the client with your app ID and your secret.
- Call a method. A refused call raises an error that carries the code, the message and the request id.
JavaScript
import { TratokLabs, TratokLabsError } from './tratok-labs.mjs';
const labs = new TratokLabs('YOUR_APP_ID', 'YOUR_SECRET');
try {
const found = await labs.searchCruises({ region: 'caribbean', limit: 3 });
console.log(found.total, found.items);
} catch (e) {
if (e instanceof TratokLabsError) console.error(e.code, e.message, e.requestId);
else throw e;
}Python
from tratok_labs import TratokLabs, TratokLabsError
labs = TratokLabs('YOUR_APP_ID', 'YOUR_SECRET')
try:
found = labs.search_cruises(region='caribbean', limit=3)
print(found['total'], found['items'])
except TratokLabsError as e:
print(e.code, e.message, e.request_id)PHP
require __DIR__ . '/TratokLabs.php';
$labs = new TratokLabs('YOUR_APP_ID', 'YOUR_SECRET');
try {
$found = $labs->searchCruises(['region' => 'caribbean', 'limit' => 3]);
echo $found['total'], "\n";
} catch (TratokLabsError $e) {
echo $e->getErrorCode(), ': ', $e->getMessage(), "\n";
}Good to know
- Keep your secret on your server. These libraries are for server code, never for a web page or a mobile app.
- Every method of the reference is there under the same name, with the same fields. In Python the names are written with underscores.
- A call made through a library is counted like any other call: free calls first, then 0.01 TRAT.
- The libraries are made from the API description, so they match the reference. New versions are announced on the What's new page.
- You may use, copy and change the files in your own projects.
- Another language? The OpenAPI file and the Postman collection describe every method.
