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-tempfileVerified import paths — ran on the pinned version, not inferred.
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.
Ensure deployment on Linux systems. If cross-platform memory-backed temporary storage is needed, consider alternative solutions or platform-specific logic.
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.
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`.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')`.
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`.
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`.
No dependency data recorded yet.