memory-tempfile
Helper functions to identify and use paths on the OS (Linux-only for now) where RAM-based tempfiles can be created.
What it is and what it does
memory-tempfile wraps Python's standard tempfile module to automatically detect and use RAM-based filesystems (tmpfs, ramfs) for temporary files on Linux. Instead of writing to physical disk, it searches a prioritized list of in-memory paths—/tmp, /run/user/{uid}, /run/shm, /dev/shm—and uses the first one that exists and is backed by a memory filesystem. This avoids the I/O overhead and wear on storage media that comes from repeated temporary file creation.
The package exposes a MemoryTempfile class that mirrors the standard tempfile API (TemporaryFile, NamedTemporaryFile, etc.) but with configurable path search order, filesystem type filters, and fallback behavior. You can customize which paths to search, add or exclude specific directories, and choose whether to fall back to the system default tempdir if no memory-based path is found. All path templates with {uid} are automatically replaced with the current user ID.
Use it for:
- Reduce I/O overhead when external tools require temporary files but you want to avoid disk writes.
- Minimize storage wear in embedded or long-running systems that create many temporary files.
- Speed up test suites that generate and discard temporary files repeatedly.
- Work with external command-line tools that write output to disk but cannot pipe directly to your application.
- Configure fallback behavior for temporary file creation in restricted or containerized environments.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Identifies and provides access to RAM-based temporary file directories on Linux, allowing you to create temporary files in memory instead of on physical disk.
Yes, if you are on Linux and need to reduce I/O overhead from temporary files. The package is simple, dependency-free, and solves a specific problem well. However, it is dormant (no releases since 2020); install it only if the stable API meets your needs and you do not expect active maintenance or new features. Not suitable for non-Linux platforms.
Install
memory-tempfile on PyPI
pip
pip install memory-tempfileuv
uv add memory-tempfilepoetry
poetry add memory-tempfileInstalling memory-tempfile
Before you install
Low friction to install. The package is dormant (last release March 2020, last commit May 2024) but has no runtime dependencies and is a pure Python wheel. Suitable for stable, narrow-scope use cases; not actively maintained for new features.
License in practice
MIT license is permissive; you can use this package freely in proprietary or open-source projects with minimal restrictions.
Quickstart
from memory_tempfile import MemoryTempfile
tempfile = MemoryTempfile()
with tempfile.TemporaryFile() as tf:
tf.write(b'data')
Linux only; requires access to /proc/self/mountinfo. Python 3.6 or later.
Verify before relying
- Whether the package correctly handles all modern tmpfs mount configurations beyond /tmp, /run/user/{uid}, /run/shm, and /dev/shm.
- Performance characteristics when searching for suitable paths on systems with many mount points.
- Compatibility with containerized or restricted environments beyond chroot and namespaces.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.6,<4.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 2,347 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 636,224/month — #5,628 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: memory_tempfile-2.2.3-py3-none-any.whl
Keywords: tempfile in RAM, tempfile in memory, file in memory, tempfs, ramdisk, /dev/shm, /run/user
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
backports.tempfileProvides the TemporaryDirectory context manager…
permissive · top 5,000 on PyPI
editorOpens your system's default text editor (or a…
permissive · top 5,000 on PyPI
pathmagicProvides File and Dir classes that wrap…
permissive · top 15,000 on PyPI
inotifyWraps Linux kernel inotify to watch directories…
copyleft · top 15,000 on PyPI
morefsmorefs provides fsspec-based filesystem…
permissive · top 15,000 on PyPI
tempenvTemporarily override environment variables…
permissive · top 15,000 on PyPI
in-placeProvides an InPlace class for reading and…
permissive · top 15,000 on PyPI
fatfs-ngfatfs-ng wraps ChaN's FatFS library to create,…
permissive · top 5,000 on PyPI
win32-setctimeSets file creation time on Windows systems via…
permissive · top 5,000 on PyPI