Skip to main content

pycaching - Geocaching for Python

Complete documentation can be found at Read the Docs.

Features

  • login to Geocaching.com

  • search caches

    • normal search (unlimited number of caches from any point)

    • quick search (all caches inside some area) - currently not working, see below

  • get cache and its details

    • normal loading (can load all details)

    • quick loading (can load just basic info but very quickly)

    • load logbook for given cache

  • get trackable details by tracking code

  • post log for a cache or a trackable

  • geocode given location

Installation

Stable version - using pip:

pip install pycaching

Dev version - manually from GIT:

git clone https://github.com/tomasbedrich/pycaching.git
cd pycaching
pip install .

Pycaching has following requirements:

Python>=3.5
requests>=2.8
beautifulsoup4>=4.9
geopy>=1.11

Pycaching tests have the following additional requirements:

betamax >=0.8, <0.9
betamax-serializers >=0.2, <0.3

Examples

Login

Simply call pycaching.login() method and it will do everything for you.

import pycaching
geocaching = pycaching.login("user", "pass")

If you won’t provide an username or password, pycaching will try to load .gc_credentials file from current directory or home folder. It will try to parse it as JSON and use the keys username and password from that file as login credentials.

{ "username": "myusername", "password": "mypassword" }

You can also provide multiple username and password tuples in a file as login credentials. The tuple to be used can be chosen by providing its username when calling pycaching.login(), e.g. pycaching.login("myusername2"). The first username and password tuple specified will be used as default if pycaching.login() is called without providing a username.

[ { "username": "myusername1", "password": "mypassword1" },
  { "username": "myusername2", "password": "mypassword2" } ]
import pycaching
geocaching = pycaching.login()  # assume the .gc_credentials file is presented

If regular programmatic login is blocked by CAPTCHA, you can reuse the gspkauth cookie from an already authenticated browser session:

import pycaching

geocaching = pycaching.login_with_cookie("copied-gspkauth-cookie")

In case you have a password manager in place featuring a command line interface (e.g. GNU pass) you may specify a password retrieval command using the password_cmd key instead of password.

{ "username": "myusername", "password_cmd": "pass geocaching.com/myUsername" }

Note that the password and password_cmd keys are mutually exclusive.

Load a cache details

cache = geocaching.get_cache("GC1PAR2")
print(cache.name)  # cache.load() is automatically called
print(cache.location)  # stored in cache, printed immediately

This uses lazy loading, so the Cache object is created immediately and the page is loaded when needed (accessing the name).

You can use a different method of loading cache details. It will be much faster, but it will load less details:

cache = geocaching.get_cache("GC1PAR2")
cache.load_quick()  # takes a small while
print(cache.name)  # stored in cache, printed immediately
print(cache.location)  # NOT stored in cache, will trigger full loading

You can also load a logbook for cache:

for log in cache.load_logbook(limit=200):
    print(log.visited, log.type, log.author, log.text)

Or its trackables:

for trackable in cache.load_trackables(limit=5):
    print(trackable.name)

Post a log to cache

geocaching.post_log("GC1PAR2", "Found cache in the rain. Nice place, TFTC!")

It is also possible to call post_log on Cache object, but you would have to create Log object manually and pass it to this method.

Search for all traditional caches around

from pycaching import Point
from pycaching.cache import Type

point = Point(56.25263, 15.26738)

for cache in geocaching.search(point, limit=50):
    if cache.type == Type.traditional:
        print(cache.name)

Notice the limit in the search function. It is because geocaching.search() returns a generator object, which would fetch the caches forever in case of a simple loop.

Geocode address and search around

point = geocaching.geocode("Prague")

for cache in geocaching.search(point, limit=10):
    print(cache.name)

Find caches in some area

from pycaching import Point, Rectangle

rect = Rectangle(Point(60.15, 24.95), Point(60.17, 25.00))

for cache in geocaching.search_rect(rect):
    print(cache.name)

If you want to search in a larger area, you could use the limit parameter as described above.

Load trackable details

trackable = geocaching.get_trackable("TB3ZGT2")
print(trackable.name, trackable.goal, trackable.description, trackable.location)

Post a log for trackable

from pycaching.log import Log, Type as LogType
import datetime

log = Log(type=LogType.discovered_it, text="Nice TB!", visited=datetime.date.today())
tracking_code = "ABCDEF"
trackable.post_log(log, tracking_code)

Get geocaches by log type

from pycaching.log import Type as LogType

for find in geocaching.my_finds(limit=5):
    print(find.name)

for dnf in geocaching.my_dnfs(limit=2):
    print(dnf.name)

for note in geocaching.my_logs(LogType.note, limit=6):
    print(note.name)

Appendix

Inspiration

Original version was inspired by these packages:

Although the new version was massively rewritten, I’d like to thank to their authors.

Authors

Authors of this project are all contributors. Maintainer is Tomáš Bedřich.

PyPI monthly downloads

Metadata

Release files for pycaching 4.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycaching 4.5.0
File Size Uploaded
pycaching-4.5.0.tar.gz 1.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycaching 4.5.0
File Interpreter ABI Platform
pycaching-4.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.7 MB

Release files / pycaching-4.5.0.tar.gz

Download URL pycaching-4.5.0.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
3a76b0e033529b6996ff1dc98bd8a006832a6cec94a7cd8bd95b679366599e57
BLAKE2b-256 checksum
How to use checksums
29319288faef11ecf0085b7d3f5e8b7d0e5e6e3a9ce9603432ab0cc4a706a1a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / pycaching-4.5.0-py3-none-any.whl

Download URL pycaching-4.5.0-py3-none-any.whl
Size 39.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39284f8958ef509f1a1a9a1f718136d7d924bcc31c15466658df17fdf4b27e3e
BLAKE2b-256 checksum
How to use checksums
8f5c1410c791457907c96f7df1592a22a1e0fab72d04cfde499829ff654d90a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

4.5.0 This release

2 release files

4.4.3

2 release files

4.4.2

2 release files

4.4.1

2 release files

4.4.0

2 release files

4.3.1

2 release files

4.2.3

2 release files

4.2.2

2 release files

4.2.1

3 release files

4.1.1

3 release files

4.1.0

3 release files

4.0.1

3 release files

4.0.0

3 release files

3.9.0

3 release files

3.8.0

3 release files

3.7.0

3 release files

3.6.9

3 release files

3.6.8

3 release files

3.6.7

3 release files

3.6.6

3 release files

3.6.5

3 release files

3.6.4

3 release files

3.6.3

3 release files

3.6.2

3 release files

3.6.1

3 release files

3.6

2 release files

3.5.4

2 release files

3.5.3

2 release files

3.5.2

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.1

2 release files

3.4

2 release files

3.3.1

1 release file

3.3

1 release file

3.2

1 release file

3.1.1

1 release file

3.1

1 release file

3.0.2

1 release file

3.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page