Skip to main content

gremllm

A slight upgrade to the Gremlins in your code, we hereby present GREMLLM. This utility class can be used for a variety of purposes. Uhm. Also please don't use this and if you do please tell me because WOW. Or maybe don't tell me. Or do.

Installation

pip install gremllm

Usage

from gremllm import Gremllm

# Be sure to tell your gremllm what sort of thing it is
counter = Gremllm('counter')
counter.value = 5
counter.increment()
print(counter.value)  # 6?
print(counter.to_roman_numerals()) # VI?

Every method call and attribute access goes through a gremllm to decide what code to execute.

Key Features

  • Dynamic Behavior: Objects implement methods and properties on-the-fly using LLM reasoning
  • Wet Mode: Method calls return living gremllm objects instead of plain values for infinite chaining
  • Verbose Mode: See exactly what code the LLM generates with verbose=True
  • Multi-Model Support: Use OpenAI, Claude, Gemini, or local models via the llm library
  • Inheritance: Child objects automatically inherit wet and verbose settings
  • Smart Error Handling: Graceful fallbacks when libraries aren't available or code fails

Configuration

Configure your preferred LLM using the llm library:

# For OpenAI (default)
llm keys set openai

# For Claude
pip install llm-claude-3
llm keys set claude

# For local models
pip install llm-ollama

You can also specify which model to use when creating a gremllm:

from gremllm import Gremllm

# Use default model (gpt-4o-mini)
counter = Gremllm('counter')

# Use specific OpenAI model
counter = Gremllm('counter', model='gpt-4o')

# Use Claude
counter = Gremllm('counter', model='claude-3-5-sonnet-20241022')

# Use local model via Ollama
counter = Gremllm('counter', model='llama2')

Examples

Basic counter (see example/counter.py):

from gremllm import Gremllm

counter = Gremllm('counter')
counter.value = 0
counter.increment()
counter.increment(5)
counter.add_seventeen()
print(counter.current_value)
print(counter.value_in_hex)
counter.reset()

Shopping cart (see example/cart.py):

from gremllm import Gremllm

# Remind me to not shop at your store
cart = Gremllm('shopping_cart')
cart.add_item('apple', 1.50)
cart.add_item('banana', 0.75)
total = cart.calculate_total()
print(f"Cart contents: {cart.contents_as_json()}")
print(f"Cart total: {total}")
cart.clear()

Wet Mode

Wet mode creates an immersive experience where method calls return gremllm objects instead of plain values, allowing infinite chaining and interaction:

from gremllm import Gremllm

# Normal mode returns plain values
counter = Gremllm('counter')
result = counter.increment()  # Returns 1 (plain int)

# Wet mode returns living gremllm objects  
wet_counter = Gremllm('counter', wet=True)
result = wet_counter.increment()  # Returns a gremllm number object
doubled = result.double()  # Can call methods on the result!
squared = doubled.square()  # Keep chaining forever!

Swimming pool simulator demonstrating wet mode (see example/wet_pool.py):

from gremllm import Gremllm

# Everything stays "wet" and alive in wet mode!
pool = Gremllm('swimming_pool', wet=True)
splash = pool.cannonball()  # Returns a living splash object
ripples = splash.create_ripples()  # Splash creates living ripples
fish = ripples.scare_fish()  # Ripples interact with fish
# Infinite emergent behavior!

Verbose Mode

Debug and understand gremllm behavior by seeing the generated code:

from gremllm import Gremllm

# Enable verbose mode to see generated code
counter = Gremllm('counter', verbose=True)
result = counter.increment()

# Output shows:
# [GREMLLM counter.increment] Generated code:
# ==================================================
# _context['value'] = _context.get('value', 0) + 1
# result = _context['value']
# ==================================================

Other notes

OMG THIS ACTUALLY WORKS

Further Reading

For background on the concept of "gremlins" in code, see: Gremlins Three Rules: An Evolutionary Analysis

Metadata

Release files for gremllm 0.2.0

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

Source distribution (sdist)

Source distribution for gremllm 0.2.0
File Size Uploaded
gremllm-0.2.0.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gremllm 0.2.0
File Interpreter ABI Platform
gremllm-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / gremllm-0.2.0.tar.gz

Download URL gremllm-0.2.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
93a8333be6a07227f36c8c151ea7375bdf02be9f64b81b0a8eded300a41049e4
BLAKE2b-256 checksum
How to use checksums
1cfad787bbb6eda424a86208fb9c0010293273898bfad98f64464332a251bb69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Release files / gremllm-0.2.0-py3-none-any.whl

Download URL gremllm-0.2.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b1655b0e39899af3504996107d32c4a6f9e19ec52cc1023920454b52771e166
BLAKE2b-256 checksum
How to use checksums
f7709553644cb905867abe77c38bcff75176af5b4c3055af227b1444c69c952e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

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