Skip to main content

datasette-low-disk-space-hook

PyPI Changelog Tests License

Datasette plugin providing the low_disk_space hook for other plugins to check for low disk space

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-low-disk-space-hook

You are unlikely to need to install this plugin directly though: it will usually be automatically be installed as a dependency of another plugin.

Usage

This plugin adds a new plugin hook to Datasette called low_disk_space(datasette=datasette).

It also adds a new space_is_running_low(datasette) utility function which can be called to check if the Datasette instance is running out of space:

from datasette_low_disk_space_hook import space_is_running_low

if await space_is_running_low(datasette):
    print("Disk space is running low")

The idea is for plugins such as datasette-upload-csvs and datasette-socrata to call this hook before writing any new data into Datasette, to check if they should continue.

Other plugins can then implement the hook to warn when Datasette is running out of space.

Working together, this will help plugins avoid filling the disk entirely with data which could cause Datasette instances to crash.

Implementing the hook

An implementation of this hook (in yet another plugin) looks like this:

from datasette import hookimpl
import shutil

@hookimpl
def low_disk_space(self, datasette):
    usage = shutil.disk_usage("/mnt")
    # Fail at 95% or more used
    if (usage.used / usage.total) > 0.95:
        return True

The plugin can also return an async function if it needs to use await as part of its execution:

from datasette import hookimpl
from somewhere import check_disk_usage_percentage_async

@hookimpl
def low_disk_space(self, datasette):
    async def inner():
        usage = await check_disk_usage_percentage_async("/mnt")
        if usage > 0.95:
            return True
    return inner

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-low-disk-space-hook
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Release files for datasette-low-disk-space-hook 0.1

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

Source distribution (sdist)

Source distribution for datasette-low-disk-space-hook 0.1
File Size Uploaded
datasette-low-disk-space-hook-0.1.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for datasette-low-disk-space-hook 0.1
File Interpreter ABI Platform
datasette_low_disk_space_hook-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / datasette-low-disk-space-hook-0.1.tar.gz

Download URL datasette-low-disk-space-hook-0.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
58604c0b94c62f4616538d0866d2d6b0880ee3d2e2d673cbdd5d4e494bab0c5d
BLAKE2b-256 checksum
How to use checksums
1bbdab3ca9e788665fdb0c4a0841c36bd6c3d6d5e279832b57f5a68bae9bd41e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / datasette_low_disk_space_hook-0.1-py3-none-any.whl

Download URL datasette_low_disk_space_hook-0.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b820561fef7fc7c6ab8275e615cc8d1ace393ea774dc15aa4cfde6f3b5a42738
BLAKE2b-256 checksum
How to use checksums
efc37d26439ef28179214af22d19d6562d2c2185a79b0ecf2aaba1d461ea5d61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.1 This release

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