Socket
Book a DemoInstallSign in
Socket

oncecall

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oncecall

Decorator to ensure a function runs only once per process

pipPyPI
Version
0.1.0
Maintainers
1

oncecall

A tiny Python decorator that ensures a function is executed only once per process.
Subsequent calls return the cached result without re-running the function.

Features

  • Simple and lightweight
  • Thread-safe
  • No external dependencies
  • Uses only Python standard library

Installation

pip install oncecall

Usage

from oncecall.once import once

@once
def initialize():
    print("Running initialization")
    return 123

initialize()
# Output:
# Running initialization

initialize()
# Output:
# (nothing printed)

The function body is executed only once. All later calls return the same result.

Typical Use Cases

  • One-time initialization logic
  • Preventing duplicate side effects
  • Expensive setup operations
  • Guarding code that should only run once

Notes

  • The execution is limited to the current Python process.
  • The cached result is stored in memory.
  • Function arguments are ignored; the function always runs only once.

Code Protection

This package uses code obfuscation to protect proprietary logic.

License

MIT License

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts