Skip to main content

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

[!IMPORTANT] You are recommanded to only use this function in .py source file, not interactive command line of python.

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)

Source distribution for py-single-file-storage 0.1.0
File Size Uploaded
py_single_file_storage-0.1.0.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-single-file-storage 0.1.0
File Interpreter ABI Platform
py_single_file_storage-0.1.0-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page