Skip to main content

CACHEDIR.TAG for Python

This library handles CACHEDIR.TAG files. Allowing any arbitrary directory to be marked as a cache directory.

A CACHEDIR.TAG file indicates a directory that contain cached data, e.g.

  • downloads
  • previews, and thumbnails
  • build artefacts, and other intermediate results

Cached data is useful, but not essential - if necessary it can be regenerated, or downloaded again. However backup programs, disk cleanup utilities, & other software can't know if an arbitrary path is cached data, unless it is marked.

A directory (and all directories within it) can be marked as a cache by writing a regular file named CACHEDIR.TAG, with the first 43 bytes being

Signature: 8a477f597d28d172789f06886806bc55

After this signature any other text can be included. The specification suggests lines of text beginning with #, encoded as UTF-8. E.g.

# This file is a cache directory tag created by (application name).
# For information about cache directory tags, see:
#	http://www.brynosaurus.com/cachedir/

This library follows that suggestion.

Installation

$ python -m pip install cachedir-tag

Usage

Create your cache directory, if necessary

>>> import os, cachedir_tag
>>> os.mkdir('/var/cache/yourapp')

Tag it, this creates a new CACHEDIR.TAG file

>>> cachedir_tag.tag('/var/cache/yourapp')

Check whether the directory is tagged

>>> cachedir_tag.is_tagged('/var/cache/yourapp')
True

Check whether a sub-directory (which may not exist yet) is tagged

>>> cachedir_tag.is_tagged('/var/cache/yourapp/somedir')
True

License

MIT

Alternatives

Operating systems and similar platforms usually have conventions about where to place cached data. A CACHEDIR.TAG file isn't needed if you follow these conventions, but it doesn't hurt either.

More information

Release files for cachedir-tag 0.0.5

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

Source distribution (sdist)

Source distribution for cachedir-tag 0.0.5
File Size Uploaded
cachedir_tag-0.0.5.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cachedir-tag 0.0.5
File Interpreter ABI Platform
cachedir_tag-0.0.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 8.6 kB

Release files / cachedir_tag-0.0.5.tar.gz

Download URL cachedir_tag-0.0.5.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
40ea1bffff8de77de7e094f70624805b2a6c5b989982094a5db4e684763a86e1
BLAKE2b-256 checksum
How to use checksums
c4cca4836b21108573851b701a3137b16eebfd589e5bdff569f5f5173af36bfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / cachedir_tag-0.0.5-py2.py3-none-any.whl

Download URL cachedir_tag-0.0.5-py2.py3-none-any.whl
Size 4.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
18af8e157251ab916277978f4337070820aced9503ce3a59171a1c296facc0fc
BLAKE2b-256 checksum
How to use checksums
baccb994cf19817f738739de6a9a0574370a1d5cd192c025fc5f5afa5c68b5d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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