Metadata-Version: 2.4
Name: rawexec
Version: 1.0.0
Summary: Fetch and execute Python scripts from any raw URL
Author-email: ZeroTeam <ytfireua@gmail.com>
License: MIT
Keywords: web,exec,remote,script,fetch,url
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# rawexec

Fetch and execute Python scripts from any raw URL.

Created by ZeroTeam.

## Installation

```bash
pip install rawexec
```

## Core Functions

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

Fetch and execute a Python script from a URL.

```python
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.

```python
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.

```python
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.

```python
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.

```python
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.

```python
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.

```python
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.

```python
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
```python
rawexec.run("https://raw.githubusercontent.com/username/repository/main/script.py")
```

### Pastebin Raw URLs
```python
rawexec.run("https://pastebin.com/raw/abc123def")
```

### Any Raw URL
```python
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

```python
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:

```python
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.
