A modern Python wrapper for the theCrag Logbook API.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25d6b109f20b7ed2001626e565d2af268114257d34e8d2bc06656ee6615650e7
|
|
| MD5 |
ee8ffafc54a1de0ab43b407e8d3d33fc
|
|
| BLAKE2b-256 |
9ad6beaac42ab6a229adeb197fbdfa7b4a2abd05a1d6014818275681d43ba50d
|
Provenance
The following attestation bundles were made for cragpy-0.2.0.tar.gz:
Publisher:
publish.yml on coderiot/cragpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cragpy-0.2.0.tar.gz -
Subject digest:
25d6b109f20b7ed2001626e565d2af268114257d34e8d2bc06656ee6615650e7 - Sigstore transparency entry: 2189517458
- Sigstore integration time:
-
Permalink:
coderiot/cragpy@8e73f10fe2d8d651e7300e5079139ecea229560e -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/coderiot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8e73f10fe2d8d651e7300e5079139ecea229560e -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
188a2b94d5a43b63e16e7c44a448a0ab46294958e91dfc6702709204be6d9b09
|
|
| MD5 |
82fb7f169d598c67d47ec8f8534d3978
|
|
| BLAKE2b-256 |
bd8c4e1cc5cc217fec7b675d5bd2c9f63d85f5a55e7655342b91775ec1225610
|
Provenance
The following attestation bundles were made for cragpy-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on coderiot/cragpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cragpy-0.2.0-py3-none-any.whl -
Subject digest:
188a2b94d5a43b63e16e7c44a448a0ab46294958e91dfc6702709204be6d9b09 - Sigstore transparency entry: 2189517481
- Sigstore integration time:
-
Permalink:
coderiot/cragpy@8e73f10fe2d8d651e7300e5079139ecea229560e -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/coderiot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8e73f10fe2d8d651e7300e5079139ecea229560e -
Trigger Event:
release
-
Statement type: