Skip to main content

A quick way to get a temporary pathlib.Path.

Project description

temppath

Provides a quick way to get a pathlib.Path file in the system-defined temporary space. temppath does not wrap tempfile.NamedTemporaryFile, as that automatically deletes on close, and does not allow the same file to be written, closed, then read in Windows, which is inconsistent with the Unix implementation. Since temppath provides pathlib.Path objects, this is not an issue.

Usage

There is a nice context manager, which will remove the path for you.

from temppath import TemporaryPathContext

with TemporaryPathContext() as t:
    t.write_text('the quick brown fox jumps over the lazy dog')
    ...
    do_something_awesome_that_reads(t)

# The file is removed when you leave the `with` context.

You also have the option to just clean it up yourself if you need more control.

from temppath import TemporaryPath

t = TemporaryPath()
t.write_text('the quick brown fox jumps over the lazy dog')
...
do_something_awesome_that_reads(t)
...
t.unlink()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

temppath-2021.236.907.tar.gz (3.0 kB view hashes)

Uploaded source

Built Distribution

temppath-2021.236.907-py3-none-any.whl (3.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page