This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Context managers for managing temporary files and directories.

with temporary.temp_dir() as d:
    ...

with temporary.temp_file(content='hello') as f:
    ...

Installation:

$ pip install temporary

Temporary Directory Examples

The temporary directory is created when entering the context manager, and deleted when exiting it:

>>> import temporary
>>> with temporary.temp_dir() as temp_dir:
...     assert temp_dir.is_dir()
>>> assert not temp_dir.exists()

This time let’s make the temporary directory our working directory:

>>> import os
>>> with temporary.temp_dir(make_cwd=True) as temp_dir:
...     assert str(temp_dir) == os.getcwd()
>>> assert not str(temp_dir) == os.getcwd()

The suffix, prefix, and parent_dir options are passed to the standard tempfile.mkdtemp() function:

>>> with temporary.temp_dir() as p:
...     with temporary.temp_dir(suffix='suf', prefix='pre', parent_dir=p) as d:
...         assert d.parent == p
...         assert d.name.startswith('pre')
...         assert d.name.endswith('suf')

This function can also be used as a decorator, with the in_temp_dir alias:

>>> @temporary.in_temp_dir()
... def my_function():
...     assert old_cwd != os.getcwd()
...
>>> old_cwd = os.getcwd()
>>> my_function()
>>> assert old_cwd == os.getcwd()

Temporary File Examples

The temporary file is created when entering the context manager and deleted when exiting it.

>>> import temporary
>>> with temporary.temp_file() as temp_file:
...     assert temp_file.exists()
>>> assert not temp_file.exists()

The user may also supply some content for the file to be populated with:

>>> with temporary.temp_file('hello!') as temp_file:
...     with temp_file.open() as f:
...         assert f.read() == 'hello!'

The temporary file can be placed in a custom directory:

>>> with temporary.temp_dir() as temp_dir:
...     with temporary.temp_file(parent_dir=temp_dir) as temp_file:
...         assert temp_file.parent == temp_dir

If, for some reason, the user wants to delete the temporary file before exiting the context, that’s okay too:

>>> with temporary.temp_file() as temp_file:
...     temp_file.unlink()
Release History

Release History

3.0.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

2.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

2.0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
temporary-3.0.0-py2.py3-none-any.whl (4.3 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel May 17, 2016
temporary-3.0.0.tar.gz (2.8 kB) Copy SHA256 Checksum SHA256 Source May 17, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting