Skip to main content

Shadow Tools

Train on regular text

from shadowtools import predict_text, train_text

texts = ["I love this game", "this is terrible", "really fun game", "I hate it"]
labels = ["positive", "negative", "positive", "negative"]

model, history = train_text(texts, labels, epochs=20)
print(predict_text(model, ["this game is fun", "I really hate this"]))
# ['positive', 'negative']

train_text learns a vocabulary from your examples. Its tokenizer keeps words, contractions, URLs, punctuation, and common two-word phrases, then converts each text into a TF-IDF number vector before training. Use SmartTokenizer yourself when you want to fit once and reuse the exact same vocabulary later.

shadow-tools is a lightweight Python toolbox for everyday apps and scripts. It keeps the basics in one clean package without trying to replace specialized libraries.

Install

pip install shadow-tools
pip install "shadow-tools[websocket]"  # optional WebSocket client

What is included

  • HTTP requests with no required third-party dependency
  • WebSocket connections through an optional extra
  • Async execution for blocking jobs
  • File and directory helpers
  • JSON and CSV reading/writing
  • Email, URL, and required-key checks
  • DNS lookup, subdomain parsing, and documentation-only test IPs
  • Provider-neutral AI prompt and tool-schema helpers
  • File and text hashing
  • UUIDs, secure tokens, and timestamp IDs
  • Slugs, snake/camel case, chunks, environment variables, and retry logic
  • Defensive security checks, secret redaction, password generation, and file verification
  • Optional PyTorch training for new MLPs or supplied local models
  • shadow command-line tool

Quick start

from shadowtools import get, write_json, is_email

response = get("https://api.github.com")
print(response.status, response.json())
write_json("output.json", {"ready": True})
assert is_email("person@example.com")

DNS, subdomains, and test IPs

from shadowtools import generate_random_ips, generate_test_ips, make_subdomain, resolve_dns

print(make_subdomain("api", "example.com"))  # api.example.com
print(resolve_dns("example.com"))
print(generate_test_ips(2))  # safe documentation-only addresses
print(generate_random_ips(5))  # globally routable public IPv4 addresses only
print(generate_random_ips(3, family=6))
print(generate_random_ips(3, include_private=True, include_special=True))

Reverse-DNS lookup for IP addresses:

from shadowtools import generate_random_ips, reverse_dns

for result in reverse_dns(generate_random_ips(5)):
    print(result)  # only IPs with hostnames are shown

# Or look up every generated IP at once.
print(reverse_dns(generate_random_ips(5)))
print(reverse_dns(generate_random_ips(5), only_hostnames=False))  # include misses

AI app helpers

from shadowtools.ai import prompt, tool_schema

message = prompt("Explain {topic} in {words} words.", topic="DNS", words=50)
search_tool = tool_schema(
    "search_docs", "Search internal documentation",
    {"query": {"type": "string"}}, required=["query"]
)

Everyday helpers

from shadowtools import hash_text, random_token, slugify, to_bool, uuid4

print(hash_text("hello"))
print(random_token())
print(uuid4())
print(slugify("Shadow Tools: Version 3!"))  # shadow-tools-version-3
print(to_bool("yes"))  # True
shadow hash settings.json
shadow uuid

Security and training

from shadowtools.security import audit_headers, redact_secrets

print(redact_secrets("Authorization: Bearer secret-value"))
print(audit_headers({"X-Content-Type-Options": "nosniff"}))

Install ML support, then train a small classifier from scratch:

pip install "shadow-tools[ml]"
from shadowtools.training import Trainer, TrainingConfig

config = TrainingConfig(
    mode="from_scratch",
    architecture={"type": "mlp", "input_size": 8, "hidden_sizes": [32, 16], "num_classes": 2},
    epochs=5,
)
trainer = Trainer(config)
history = trainer.fit(train_loader, validation_loader)

For normal lists, use the short root-level API—no PyTorch imports or loaders:

from shadowtools import train

model, history = train(
    features=[[0, 1], [1, 1], [0, 0], [1, 0]],
    labels=[1, 1, 0, 0],
    epochs=10,
)
print(history)
shadow get https://api.github.com --json
shadow json-format settings.json

WebSockets

from shadowtools.websocket import connect

socket = connect("wss://example.com/socket")
socket.send("hello")
print(socket.recv())
socket.close()

Release

Build locally with python -m build, then publish only after reviewing the generated distributions and confirming the PyPI project name is available.

License

MIT

Metadata

Release files for shadow-tools 0.5.1

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

Source distribution (sdist)

Source distribution for shadow-tools 0.5.1
File Size Uploaded Provenance Actions
shadow_tools-0.5.1.tar.gz 16.4 kB Without provenance Details for shadow_tools-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shadow-tools 0.5.1
File Interpreter ABI Platform Actions
shadow_tools-0.5.1-py3-none-any.whl Python 3 none any Details for shadow_tools-0.5.1-py3-none-any.whl

Total release size: 37.6 kB

Release files / shadow_tools-0.5.1.tar.gz

Download URL shadow_tools-0.5.1.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1ac13d4fb94d2ac8ae04073e5de576bf1c4629c8366ae0b3d72e4504904bc1eb
BLAKE2b-256 checksum
How to use checksums
acb9acf8c3ad9e9702de5dee44a5ba63e9388b9be71c6686377a78529e7e4519
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / shadow_tools-0.5.1-py3-none-any.whl

Download URL shadow_tools-0.5.1-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6686d58bac341f6a86af4aa2285e99488e5b0cb94c2bd9b5450d58923f0b648
BLAKE2b-256 checksum
How to use checksums
0b67183a25c84910abc7e670962288a8dc25563427de24370024bdc78d2dbf9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for shadow-tools 0.5.1

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