Skip to main content

Python library for synchronous HTTP calls to the Trackbear API (https://help.trackbear.app/api)

Project description

Python 3.10 | 3.11 | 3.12 | 3.13 | 3.14 PyPI - Version Python tests

pre-commit.ci status Code style: black Nox

trackbear-api


Python library for synchronous HTTP calls to the Trackbear API (https://help.trackbear.app/api)

Deveploment in progress, expect breaking changes frequently until version 0.1.0

Installation

python -m pip install trackbear-api

Environment Variables

The following environment variables allow you to configure the TrackBearClient outside of code. All variables listed below can also be set during the initialization of the TrackBearClient as well.

Variable Description Has Default Default
TRACKBEAR_API_TOKEN Your secret API token False
TRACKBEAR_API_URL The URL of the TrackBear API True https://trackbear.app/api/v1/
TRACKBEAR_API_AGENT The User-Agent header sent with requests True trackbear-api/0.x.x (https://github.com/Preocts/trackbear-api) by Preocts

Example Use

The TrackBearClient give you all of the access to the TrackBear API. Various routes of the API, such as Projects, are available through the TrackBearClient from their respective attribute.

from trackbear_api import TrackBearClient

# Assumes TRACKBEAR_API_TOKEN is set in the environment
client = TrackBearClient()

try:
    projects = client.project.list()

except APIResponseError:
    print("Failed to get projects")
    raise SystemExit(1)

print(f"| {'Project Id':^12} | {'Title':^30} | {'Word Count':^12} |")
print("-" * 64)
for project in projects:
    print(f"| {project.id:<12} | {project.title:<30} | {project.totals.word:<12} |")

Exceptions

The library defines a handful of useful custom exceptions.

import trackbear_api.exceptions

ModelBuildError(Exception)

Raised when building a dataclass model from the API response fails. This can indicate the expected response has changed from the observed response. The exception contains the model name that failed and the data the model attempted to build with. Both are vital for bug reports.

Attribute Type Description
data_string str The data which caused the model build to fail
model_name str The name of the model that failed

APIResponseError(Exception)

The base class for all API response errors. Raised by all provider methods when the API returns an unsuccessful response.

Attribute Type Description
status_code int HTTP status code returned by the API
code str Error code provided by the API
message str Human readable error message provided by the API

Library API

The library's API is build to match TrackBear's API general structure.

https://help.trackbear.app/api/

Projects

Provider Method Description
TrackBearClient.project Contains helper methods for all Project related routes
Method Description
.list() Get all projects
.get() Get a project by specific id
.save() Create or update projects
.delete() Delete a project by its id

Bare Access

Bare access to the API allows you to escape from the structured return models and call routes directly. These methods return a TrackBearResponse object.

Provider Method Description
TrackBearClient.bare Escape hatch allowing manually defined calls to API
Method Description
.get() HTTP GET to the TrackBear API
.post() HTTP POST to the TrackBear API
.patch() HTTP PATCH to the TrackBear API
.delete() HTTP DELETE to the TrackBear API

TrackBearResponse object

Attribute Type Description
.success bool True or False if the request was succesful.
.data Any API response if success is True
.error.code str Error code if success is False
.error.message str Error message if success is False
.status_code int The HTTP status code of the response
.remaining_requests int Number of requests remaining before rate limits apply
.rate_reset int Number of seconds before remaining_requests resets

Rate Limiting

Rate limiting is defined by the TrackBear API here: https://help.trackbear.app/api/rate-limits

This library does not presently enforce the rate limits.

Logging

All loggers use the name trackbear-api. No handlers are defined by default in this library.

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

trackbear_api-0.0.3.tar.gz (53.4 kB view details)

Uploaded Source

Built Distribution

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

trackbear_api-0.0.3-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file trackbear_api-0.0.3.tar.gz.

File metadata

  • Download URL: trackbear_api-0.0.3.tar.gz
  • Upload date:
  • Size: 53.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for trackbear_api-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4c14e1df9f429a524a7a9954deb283c8cef2d0231d4713c232ea4a81367ba578
MD5 de81d6947f25a5c897bdbd2ff3a079bb
BLAKE2b-256 dff77a5916161a0803e4e4b4c25c5eccc87e2b0e3754982a15d1770c2939955f

See more details on using hashes here.

Provenance

The following attestation bundles were made for trackbear_api-0.0.3.tar.gz:

Publisher: pypi-publish.yml on Preocts/trackbear-api

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

File details

Details for the file trackbear_api-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: trackbear_api-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for trackbear_api-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1e1de30ae98311d30233e2562b741431955fcea5dc01611bdd3cc5c8d59a77a9
MD5 1b8b4e40e7757677165e806fe8e524ab
BLAKE2b-256 80b2138d9556a9f6fa9d1bd14b6913de7ae179d4e8598b1b1043ed241f91c8ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for trackbear_api-0.0.3-py3-none-any.whl:

Publisher: pypi-publish.yml on Preocts/trackbear-api

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