forbiddenfruit
Patch python built-in objects
What it is and what it does
Forbiddenfruit is a CPython-specific library that uses the Python C API to dynamically patch built-in types (int, str, list, etc.) with new methods and attributes at runtime. It was originally created to support fluent assertion libraries similar to RSpec Expectations, but has been used for spying, profiling integration, and other runtime introspection tasks.
The library provides three main functions: `curse()` to add a method to a built-in type, `reverse()` to remove a cursed attribute, and `cursed()` as a context manager or decorator to temporarily patch a type and automatically clean up on exit. Because it operates at the C API level, it can modify types that are normally immutable from pure Python. However, this power comes with significant constraints: it only works on CPython, requires compilation during installation, and the last release was in early 2021.
Use it for:
- Implement fluent assertion APIs for testing libraries similar to RSpec Expectations.
- Add introspection or profiling hooks to built-in types without modifying their source.
- Temporarily extend built-in behavior within a specific code block using the context manager.
- Spy on or intercept calls to built-in type methods for debugging or monitoring.
- Prototype or experiment with language-like extensions to Python's core types.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Forbiddenfruit allows you to dynamically add methods and attributes to Python's built-in types (like int, str, list) at runtime, using the CPython C API.
Yes, if you need to dynamically extend built-in types and are committed to CPython. No, if you use PyPy or other implementations, or prefer to avoid C compilation during install. The dual MIT/GPLv3 license is permissive, but the high install friction and age of the last release mean you should verify compatibility with your specific Python version before relying on it in production.
Install
forbiddenfruit on PyPI
pip
pip install forbiddenfruituv
uv add forbiddenfruitpoetry
poetry add forbiddenfruitInstalling forbiddenfruit
Before you install
High install friction: the package requires compilation against the CPython C API and is only compatible with CPython. Last release was 2021-01-16, but the repository remains active with recent commits.
License in practice
Dual-licensed under GPLv3+ and MIT; you may choose either license. This dual licensing provides flexibility—use MIT for permissive integration or GPLv3+ if you prefer copyleft terms.
Quickstart
from forbiddenfruit import curse, reverse
def greet(self):
return f"Hello from {self}"
curse(str, "greet", greet)
print("world".greet()) # Hello from world
reverse(str, "greet")
Requires CPython (not PyPy, Jython, or other implementations) and a C compiler to build the extension module during installation.
Verify before relying
- Whether the package works reliably on modern Python versions beyond those explicitly tested (2.7, 3.0, 3.3–3.7).
- Stability and compatibility with CPython versions released after the last 2021-01-16 release.
- Whether reverse() correctly restores pre-existing built-in attributes or only removes added ones.
Package facts
| License | not declared (unclear) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | actively maintained — 2,036 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,451,765/month — #3,058 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: forbiddenfruit-0.1.4.tar.gz
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
noneA library providing additional utilities and…
permissive · top 15,000 on PyPI
patchyPatchy modifies Python functions at runtime by…
permissive · top 5,000 on PyPI
jsonableProvides an abstract base class for defining…
permissive · top 15,000 on PyPI
wraptwrapt provides a Python module for building…
permissive · top 100 on PyPI
django-stubs-extProvides runtime monkey-patching extensions for…
permissive · top 5,000 on PyPI
mixed-methodsProvides a decorator that lets a single method…
permissive · top 15,000 on PyPI
cintWraps ctypes integer types to perform…
permissive · top 5,000 on PyPI
pyarrow-hotfixDisables the CVE-2023-47248 security…
permissive · top 1,000 on PyPI
argparse-extExtends Python's standard argparse module with…
copyleft · top 15,000 on PyPI