Skip to main content

safescope

Build Status PyPI PyPI - Python Version License

safescope is a small python package useful for development in jupyter notebooks. The goal is to prevent functions from using global variables and instead raise a NameError. This is achieved by mimicking a module, and define all functions in that module (named side_scope).

Example

The main part of safescope is the decorator @safescope. This mimics writing the function in a file side_scope.py and importing this function to the notebook. Hence, functions decorated with @safescope will not have access to variables declared in the notebook environment.

In the example below, only foo(1) will execute, as bar(1) returns a NameError.

from safescope import safescope

x = 9

def foo(y):
    return x + y

@safescope
def bar(y):
    return x + y

foo(1) # Returns  10
bar(1) # Raise "NameError: name 'x' is not defined"

By using Imports, the imports are added to both the main scope and the side_scope, making them available for the functions decorated with @safescope.

from safescope import safescope, Imports

with Imports():
    import numpy as np

@safescope
def arange(n):
    return np.arange(n)

arange(4) # Returns array([0, 1, 2, 3])

Installation

safescope can either be installed from pypi with pip/pip3:

pip install safescope

or from github with:

pip install git+git://github.com/havakv/safescope.git

or from source by cloning the repo:

git clone https://github.com/havakv/safescope.git
cd safescope
python setup.py install

Metadata

Release files for safescope 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for safescope 0.2.6
File Size Uploaded Provenance
safescope-0.2.6.tar.gz 4.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for safescope 0.2.6
File Interpreter ABI Platform
safescope-0.2.6-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 8.8 kB

Release files / safescope-0.2.6.tar.gz

Download URL safescope-0.2.6.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
55e09e7068182746e3de4f127ea6bf25bd1205ff8db0baaafe0d9bb17b6d3e3c
BLAKE2b-256 checksum
How to use checksums
e2b284cb268f62e8c9a04d060bc0ec51178e131245ebc2d37658fb8078b8bfaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / safescope-0.2.6-py2.py3-none-any.whl

Download URL safescope-0.2.6-py2.py3-none-any.whl
Size 4.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3726599d268e9f9cbc48ca31fd35a0b73fe26598e2cc93347fe221f67f9c3669
BLAKE2b-256 checksum
How to use checksums
0457bf87f8204a4b21b79e8cfc7c7bb7eedbc475d2c5d4937102dd3519ebf734
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Security for safescope 0.2.6

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.

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