skillfed

memory-tempfile

Helper functions to identify and use paths on the OS (Linux-only for now) where RAM-based tempfiles can be created.

memory-tempfile v2.2.3 636.2K downloads/30d#5,628 on PyPI41
Permissive license MIT DORMANT released

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-tempfile

uv

uv add memory-tempfile

poetry

poetry add memory-tempfile

Installing 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

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8

Tags

ram temporary files linuxin-memory tempfiletmpfs tempdirramdisk temporary storagedev shm tempfilefast temporary filesmemory-based tempdir
linux-onlyio-optimizationtempfile-management

More Utilities packages