Skip to main content

USTDownloadCache

GitHub license GitHub tag (latest by date) GitHub last commit

About

The USTDownloadCache is used by the Ubuntu Security Team to improve the runtime of other packages by caching certain JSON files.

Using USTDownloadCache

Example:

import logging
from ust_download_cache import USTDownloadCache

logger = logging.getLogger("")
download_cache = USTDownloadCache(logger)

url = "URL_GOES_HERE"
data = download_cache.get_data_from_url(url)
metadata = download_cache.get_cache_metadata_from_url(url) # used by USTDownloadCache

Extracting zipped files

USTDownloadCache has the ability to download, extract, and cache either bz2 or gz archives. These files are extracted and stored uncompressed so that the data can be accessed as quickly as possible.

Metadata

The USTDownloadCache relies on metadata contained within the file it is downloading/caching. The JSON must supply a "metadata" key, which provides a timestamp (seconds since the Unix epoch) and time to live (ttl) in seconds. The cached version of the file is considered to be expired when timestamp + ttl > now

{
    "metadata": {
        "timestamp": 1591887905,
        "ttl": 3600,
        "version": "1.0"
    },
    "data": {
        "name1": "value1",
        "name2": "value2"
    }
}

Installation

From Source

To install from source, you can clone this repository and install USTDownloadCache:

$> git clone https://github.com/canonical/ust-download-cache
$> pip3 install --user ./ust-download-cache/

As a dependency

As USTDownloadCache is not in PyPI at the moment, you must use the github tarball in your setup.py:

install_requires = [
        "ust-download-cache @ https://github.com/canonical/ust-download-cache/archive/v1.0.1.tar.gz",
]

Development

Installing precommit hooks

To install the precommit hooks, run

pip3 install --user pre-commit
~/.local/bin/pre-commit install

Running the test suite

You can run the automated test suite by running

$> python3 -m pytest

An HTML code coverage report will be generated at ./htmlcov. You can view this with any web browser (e.g. firefox ./htmlcov/index.html).

Release files for UST-Download-Cache 2.1.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 UST-Download-Cache 2.1.0
File Size Uploaded
UST Download Cache-2.1.0.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for UST-Download-Cache 2.1.0
File Interpreter ABI Platform
UST_Download_Cache-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.7 kB

Release files / UST Download Cache-2.1.0.tar.gz

Download URL UST Download Cache-2.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f35b2be2d00d6f980700c6cdc138316c1f1c8ab1ebea9dc675e41839455d7713
BLAKE2b-256 checksum
How to use checksums
cddd5649a425f64848f0403138a3e1bd001f6db2d2095460e5dd0ed90bf01755
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

Release files / UST_Download_Cache-2.1.0-py3-none-any.whl

Download URL UST_Download_Cache-2.1.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
064e892d2e56f308a470967fdf35588f5d960ef823e6df6ee3f00d7659aef0fb
BLAKE2b-256 checksum
How to use checksums
83f8f6f7eea9dc81cda4c7f4afeb9142dbf506e30e5f120b766937ddef507cc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.1.0

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