Skip to main content

Fetch and execute Python scripts from any raw URL

Project description

rawexec

Fetch and execute Python scripts from any raw URL.

Created by ZeroTeam.

Installation

pip install rawexec

Core Functions

rawexec.run(url, *, timeout=10, cache=False, globals_=None)

Fetch and execute a Python script from a URL.

import rawexec

# Execute a script from Pastebin
rawexec.run("https://pastebin.com/raw/abc123")

# Execute with custom globals
my_globals = {"name": "Alice"}
rawexec.run("https://example.com/script.py", globals_=my_globals)

# Use caching
rawexec.run("https://example.com/script.py", cache=True)

rawexec.load(url, module_name=None, *, timeout=10, cache=False)

Fetch a script and return it as an importable module.

import rawexec

# Load as module
mod = rawexec.load("https://raw.githubusercontent.com/user/repo/main/script.py")
print(mod.hello_world())

# Load with custom module name
utils = rawexec.load("https://raw.githubusercontent.com/user/repo/main/utils.py", module_name="myutils")
utils.helper_function()

rawexec.fetch(url, *, timeout=10, cache=False)

Return source code as string without executing.

import rawexec

# Get source code
source = rawexec.fetch("https://raw.githubusercontent.com/user/repo/main/script.py")
print(source)

rawexec.clear_cache()

Clear the in-memory cache.

import rawexec

# Clear cached content
rawexec.clear_cache()

Extra Functions

rawexec.watch(url, interval=60)

Re-fetch and re-run a script every X seconds automatically.

import rawexec
import time

# Watch a script every 30 seconds
thread = rawexec.watch("https://raw.githubusercontent.com/user/repo/main/monitor.py", interval=30)

# Keep the main thread alive
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("Stopped watching")

rawexec.run_all([url1, url2, url3])

Fetch and run multiple scripts in order.

import rawexec

# Run multiple scripts
urls = [
    "https://raw.githubusercontent.com/user/repo/main/setup.py",
    "https://raw.githubusercontent.com/user/repo/main/main.py",
    "https://raw.githubusercontent.com/user/repo/main/cleanup.py"
]
rawexec.run_all(urls)

rawexec.preview(url)

Print the source code without executing it.

import rawexec

# Preview a script
rawexec.preview("https://raw.githubusercontent.com/user/repo/main/script.py")

rawexec.install_imports(url, *, timeout=10, cache=False, upgrade=False, user=False)

Detect and install missing imports from a remote script.

import rawexec

# Install missing dependencies
installed = rawexec.install_imports("https://raw.githubusercontent.com/user/repo/main/script.py")
print(f"Installed packages: {installed}")

# Install with upgrade and user flags
rawexec.install_imports("https://raw.githubusercontent.com/user/repo/main/script.py", 
                       upgrade=True, user=True)

URL Examples

The package works with any raw URL that returns Python code:

GitHub Raw URLs

rawexec.run("https://raw.githubusercontent.com/username/repository/main/script.py")

Pastebin Raw URLs

rawexec.run("https://pastebin.com/raw/abc123def")

Any Raw URL

rawexec.run("https://example.com/files/myscript.py")

Error Handling

The package raises clear RuntimeError exceptions when:

  • URL is not reachable
  • HTTP status code is not 200
  • Content is not valid UTF-8 text
  • Network errors occur
import rawexec

try:
    rawexec.run("https://example.com/nonexistent.py")
except RuntimeError as e:
    print(f"Error: {e}")

Caching

Enable caching to avoid re-fetching the same URL:

import rawexec

# First call fetches from URL
rawexec.run("https://example.com/script.py", cache=True)

# Subsequent calls use cached content
rawexec.run("https://example.com/script.py", cache=True)

# Clear cache when needed
rawexec.clear_cache()

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rawexec-1.0.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rawexec-1.0.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file rawexec-1.0.0.tar.gz.

File metadata

  • Download URL: rawexec-1.0.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for rawexec-1.0.0.tar.gz
Algorithm Hash digest
SHA256 97e626728b9da50914e975d1156e253446bf6da92e91281b4e09714a3144b1be
MD5 7b7b1c917f2b422a50f101fb55db89fd
BLAKE2b-256 e1ba3a33bd5d1171a7b8c007a7d506efcb5b5ea68d57c13c10abcfe709cfcca3

See more details on using hashes here.

File details

Details for the file rawexec-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rawexec-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for rawexec-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64105b67bb6cb8eed9cbd5650af8e1cce2b8009d4e97ddb3518ff1b60dd4e582
MD5 9fd815a656598eca68f03abfdd4f1fc7
BLAKE2b-256 9f51120be2826b22fe051cd22a15aad97180567653cac40c983f5b19285bd0d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page