Registry / devops / memory-tempfile

memory-tempfile

JSON →
library2.2.3pypypi✓ verified 85d ago

memory-tempfile (version 2.2.3) is a Python library that provides helper functions to identify and utilize paths on Linux-based operating systems where RAM-based temporary files can be created. It extends Python's standard `tempfile` module to prioritize memory-backed filesystems like `tmpfs` or `ramfs` for temporary storage, aiming to improve performance by avoiding disk I/O. The project has a stable, albeit infrequent, release history with the current version released in 2019.

pip install memory-tempfile
INSTALL
IMPORT
SIG · MEMORY-TEMPFILE
M
memory-tempfile
devopspythonv2.2.3
Install
1.6s avg
Import
21ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.022s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.020s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MemoryTempfile
from memory_tempfile import MemoryTempfile

This example demonstrates how to create a temporary file and a temporary directory using `MemoryTempfile`, which will attempt to use a RAM-based filesystem. The resources are automatically cleaned up using context managers.

from memory_tempfile import MemoryTempfile import os tempfile_manager = MemoryTempfile() # Create a temporary file in a memory-backed filesystem with tempfile_manager.TemporaryFile(mode='w+t') as tf: tf.write('Hello from memory tempfile!') tf.seek(0) content = tf.read() print(f"Read from temp file: {content}") # Create a temporary directory in a memory-backed filesystem with tempfile_manager.TemporaryDirectory() as td: print(f"Temporary directory created at: {td}") # You can create files inside this directory file_path = os.path.join(td, 'my_data.txt') with open(file_path, 'w') as f: f.write('Data in temp directory.') print(f"File created in temp directory: {file_path}") # Directory and its contents are automatically removed when exiting the 'with' block
Debug
Known issues
gotchaThe `memory-tempfile` library is currently designed and tested for Linux-only environments. Its core functionality relies on identifying and using specific Linux-based RAM filesystems (e.g., tmpfs, ramfs).
fix
Ensure deployment on Linux systems. If cross-platform memory-backed temporary storage is needed, consider alternative solutions or platform-specific logic.
affects: All versions
breakingIf no suitable memory-based filesystem path (like tmpfs or ramfs) is found, and the `fallback` argument to `MemoryTempfile` constructor is set to `False`, a `RuntimeError` will be raised.
fix
Set `fallback=True` to allow falling back to the default system temporary directory, or provide a specific fallback path (e.g., `fallback='/path/to/disk/temp'`). Check `MemoryTempfile().tempdir` before creating files if `fallback=False` is critical.
affects: All versions
gotchaPaths containing the string `{uid}` (e.g., `/run/user/{uid}`) are automatically replaced by the current user's ID by the library. This behavior is intentional but developers should be aware of this dynamic path resolution.
fix
Account for `{uid}` replacement in path expectations, especially if constructing paths manually or validating them. The resolved path can be accessed via `tempfile_manager.tempdir`.
affects: All versions
Errors
Common errors & fixes
RuntimeError: No suitable memory-based tempdir found
This error occurs when `memory-tempfile` cannot locate an existing and accessible memory-backed filesystem (like tmpfs or ramfs) to use for temporary files, and the `fallback` option was explicitly set to `False`.
fix
Initialize `MemoryTempfile` with `fallback=True` to allow it to use the system's default temporary directory if a memory-based one isn't available: `tempfile_manager = MemoryTempfile(fallback=True)`. Alternatively, provide a specific fallback path: `tempfile_manager = MemoryTempfile(fallback='/var/tmp')`.
Permission denied: '/run/user/1000/...' (or similar path)
Despite being a memory-based path, underlying filesystem permissions can still prevent the user from creating or writing files. This could be due to incorrect user permissions or restrictive system configurations.
fix
Verify the permissions of the identified temporary directory (e.g., `/run/user/<your_uid>`, `/dev/shm`) for the user running the Python process. If using custom `preferred_paths` or `additional_paths`, ensure those directories are writable. As a workaround, consider using the `fallback=True` option or specifying a known writable directory via `dir` argument to `TemporaryFile` or `TemporaryDirectory`.
IOError: [Errno 28] No space left on device
Even though `memory-tempfile` uses RAM-based filesystems, these filesystems typically have a configured size limit. If too many or too large temporary files are created, this limit can be exhausted, leading to 'no space left' errors.
fix
Monitor the usage of your memory-based temporary filesystems (e.g., `df -h /dev/shm` on Linux). Ensure proper cleanup of temporary files, especially when not using context managers. If large files are expected, increase the size limit of the tmpfs mount (usually done via `/etc/fstab`) or consider `fallback=True`.
Upgrade
Version history
2.2.3latest on PyPI · released Mar 11, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
memory-tempfile — pip install memory-tempfile · libregistry