py_single_file_storage
Store some information within the current .py file for the distribution of a single-source-file Python application.
Application Scenarios
py_single_file_storage is a lightweight utility designed for storing persistent data directly within a single Python source file. It is specially optimized for distributing standalone, single-file Python applications where no external configuration files, databases, or auxiliary resources are desired.
By embedding state and runtime data inside the .py file itself, this library enables scripts to retain information across executions — such as execution counters, user preferences, cached parameters, or one-time setup flags — without creating additional files on the filesystem. It works reliably in scripted environments while avoiding conflicts in interactive Python shells, making it ideal for portable tools, utility scripts, self-contained CLI programs, and lightweight deployment scenarios where clean distribution and minimal footprint are priorities.
Installation
pip install py_single_file_storage
Usage
from py_single_file_storage import PSFS_Object
import sys
import os
in_script = not hasattr(sys, 'ps1')
if in_script:
filepath = __file__
else:
filepath = os.path.join(os.getcwd(), "a.py")
open(filepath, "a").close()
# a simple program to count the number of launch for script
with PSFS_Object(filepath) as mem:
data = mem.get()
if data.get("run_time") is None:
data["run_time"] = 0
data["run_time"] += 1
mem.put(data)
print(f"run time now: {data["run_time"]}")
Metadata
Release files for py-single-file-storage 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_single_file_storage-0.1.0.tar.gz | 3.2 kB | Without provenance | Details for py_single_file_storage-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_single_file_storage-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for py_single_file_storage-0.1.0-py3-none-any.whl |
Total release size: 7.3 kB
Release files / py_single_file_storage-0.1.0.tar.gz
| Download URL | py_single_file_storage-0.1.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd404d7d0a95d95d9a41f97084c0ee46dbef37ba0a6d5aebe0cb28eb257f7f60
|
|
BLAKE2b-256 checksum How to use checksums |
1d8d7f852599d306c25ca1d191d8c8b54e01d151dc91a9c2daad82831830d4d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.13.12 Windows/11
|
Release files / py_single_file_storage-0.1.0-py3-none-any.whl
| Download URL | py_single_file_storage-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bacb7b156a3f030ddd707a55d49d60f534003bb27fbb78aeb6652025f929dfad
|
|
BLAKE2b-256 checksum How to use checksums |
ae033bb94abbe8c9c84a6936d8cd491cec9c43aac62ab495d3469126c68794f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.13.12 Windows/11
|
Security for py-single-file-storage 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.