Assign emotional personalities to Python functions via AST + runtime analysis
Project description
emotion
Give your Python functions feelings.
A Python decorator that assigns emotional personalities to functions based on code structure and runtime behaviour.
What It Does
| Feature | Description |
|---|---|
| 🎭 Emotion assignment | Each function gets an emotion based on its code structure: complexity, keywords, recursion, async, error-handling, etc. |
| 🌈 Rich colorful CLI | Every call prints ANSI 256-color output: emotion chip, intensity bar, valence badge, wall time, CPU time, memory, error count |
| 💬 Inter-function conversation | When two conversation=True functions run concurrently, they talk to each other in the terminal |
| 🔄 Emotion drift | Emotions evolve every 10 calls based on error rate, latency, and frequency |
| 🤝 Social relationships | Functions develop feelings toward each other: friendship, jealousy, respect, anger, pity… |
| 🔬 Deep profiling | Wall time, CPU time, heap delta, heap peak via tracemalloc — O(1) overhead per call |
| 🕸️ Call graph | Static AST scan builds a project-wide call graph; see who calls whom |
Quick Demo
from emotion import emotion
@emotion
def calculate_total(numbers: list) -> float:
return sum(n for n in numbers if n > 0)
@emotion(conversation=True)
def validate_user(user_id: int, role: str) -> bool:
try:
assert user_id > 0
assert role.strip()
return True
except AssertionError:
return False
calculate_total([1, 2, 3, 4, 5])
validate_user(42, "admin")
Terminal output:
😊 calculate_total ▸ glad [joy] ░···· ▲ +
▸ awakened Sums positive numbers and returns the total.
│ ✓ done 😊 calculate_total #1 ⏱ 0.1ms cpu 0.01ms mem +0.0KB cc=2 err=0
Installation
pip install emotion
Or clone and run directly:
git clone https://github.com/itsmohitrohilla/emotion.git
cd emotion
python examples/quickstart.py
The @emotion Decorator
# Bare — simplest form
@emotion
def my_function(x):
return x * 2
# With options
@emotion(enabled=True, conversation=True, verbose=True)
def my_function(x):
return x * 2
| Option | Default | Description |
|---|---|---|
enabled |
True |
False → zero overhead, function unchanged |
conversation |
False |
Functions talk to each other when running concurrently |
verbose |
True |
False → silent mode, metrics still collected |
Public API
from emotion import (
emotion, # decorator
build_report, # build_report(name) → FunctionReport
all_reports, # all_reports(sort_by="call_count") → list
describe, # describe(func) → one-line string
callers_of, # callers_of(name) → list of caller names
callees_of, # callees_of(name) → list of callee names
scan_directory, # scan_directory(path) → build call graph
get_all_names, # list of all registered function names
get_data, # get_data(name) → raw registry dict
)
Requirements
- Python 3.11+
- Zero external dependencies — pure stdlib
- Optional: Ollama with
phi3.5:minifor AI-generated descriptions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
checkemotion-0.2.1.tar.gz
(81.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file checkemotion-0.2.1.tar.gz.
File metadata
- Download URL: checkemotion-0.2.1.tar.gz
- Upload date:
- Size: 81.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
735c2d928b6fe1a6d6562cffe8fe169375771c18ae0c431cd8ce0288557a9790
|
|
| MD5 |
e19beeb27c01ce96aa5449948bf07481
|
|
| BLAKE2b-256 |
6fc0a4e8c9497efa01eb8d104f76ad02c9cbfab4efa86dc0c989e201c85887d2
|
File details
Details for the file checkemotion-0.2.1-py3-none-any.whl.
File metadata
- Download URL: checkemotion-0.2.1-py3-none-any.whl
- Upload date:
- Size: 62.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d66d98b92a53e5db50a8d5823223ceceecbd7b3cec2ac88776d8f7f25adbba9d
|
|
| MD5 |
3294d3bf561063a792b644929de249dc
|
|
| BLAKE2b-256 |
de853fa8a0b6227dc1c6513ddca1e63ff61dc5bedfe9350f461551442d7b479a
|