Skip to main content

A modern Python wrapper for the theCrag Logbook API.

Project description

CI PyPI

cragpy

A modern Python wrapper for the theCrag Logbook API.

Installation

Install dependencies locally or install the package in editable mode:

# Clone the repository
git clone https://github.com/coderiot/pycrag.git
cd pycrag

# Install package with test/development dependencies
pip install -e ".[test]"

Updating cragpy

# Update the package
pip install --upgrade cragpy

Usage

from cragpy import TheCragClient

# Initialize client
client = TheCragClient(api_key="YOUR-API-KEY")

# Fetch logbook ascents
# Optional parameters:
# - page: int
# - since: int 
logbook = client.get_logbook(page=1)

# Read account metadata
if logbook.account:
    print(f"Climber Profile: {logbook.account.name} (@{logbook.account.login})")
    print(f"Total Ascents: {logbook.account.ascentCount}")
    print(f"Cumulative Height Climbed: {logbook.account.heightClimbed}m")

# Loop through ascents
for ascent in logbook.ascents:
    print(f"Ascent ID: {ascent.id}")
    print(f"Logged Date: {ascent.logDate}")
    print(f"Route Name: {ascent.route.name if ascent.route else 'N/A'}")
    print(f"Grade: {ascent.route.grade if ascent.route else 'N/A'}")
    print(f"Tick style: {ascent.tick.name if ascent.tick else 'N/A'}")
    print("-" * 20)

Rate-Limiting & Retries

Customizing the requests-per-second limit

client = TheCragClient(api_key="YOUR-API-KEY", requests_per_second=1.0)

CLI Usage

Use the cragpy CLI tool to fetch your complete logbook.

# Export logbook to JSON file
cragpy --api-key YOUR-API-KEY --output my_logbook.json

# or using environment variable for API key
export THECRAG_API_KEY="YOUR-API-KEY"
cragpy -o my_logbook.json

# Output prints to stdout formatted in JSON.
cragpy --api-key YOUR-API-KEY

# Incremental Updates: Fetch only ascents after a specific epoch timestamp
cragpy --api-key YOUR-API-KEY --since 1700000000

# Export logbook in CSV format instead of JSON
cragpy --api-key YOUR-API-KEY --format csv -o my_logbook.csv

Running with uv

With uv you can use the CLI without installing the package first:

# Run directly from PyPI without installing (via uvx)
uvx cragpy --api-key YOUR-API-KEY -o my_logbook.json

# Or install it as a persistent tool on your PATH
uv tool install cragpy
cragpy --api-key YOUR-API-KEY -o my_logbook.json

Inside a clone of this repository, uv run sets up the environment and runs the CLI in one step:

uv run cragpy --api-key YOUR-API-KEY -o my_logbook.json

Running Tests & Formatting

Run the test suite using pytest:

pytest

Run code quality check and formatters using ruff:

ruff check
ruff format

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

cragpy-0.2.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

cragpy-0.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file cragpy-0.2.0.tar.gz.

File metadata

  • Download URL: cragpy-0.2.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cragpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 25d6b109f20b7ed2001626e565d2af268114257d34e8d2bc06656ee6615650e7
MD5 ee8ffafc54a1de0ab43b407e8d3d33fc
BLAKE2b-256 9ad6beaac42ab6a229adeb197fbdfa7b4a2abd05a1d6014818275681d43ba50d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cragpy-0.2.0.tar.gz:

Publisher: publish.yml on coderiot/cragpy

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

File details

Details for the file cragpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cragpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cragpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 188a2b94d5a43b63e16e7c44a448a0ab46294958e91dfc6702709204be6d9b09
MD5 82fb7f169d598c67d47ec8f8534d3978
BLAKE2b-256 bd8c4e1cc5cc217fec7b675d5bd2c9f63d85f5a55e7655342b91775ec1225610

See more details on using hashes here.

Provenance

The following attestation bundles were made for cragpy-0.2.0-py3-none-any.whl:

Publisher: publish.yml on coderiot/cragpy

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