skillfed

forbiddenfruit

Patch python built-in objects

forbiddenfruit v0.1.4 2.5M downloads/30d#3,058 on PyPI883
License unclear Active released

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 forbiddenfruit

uv

uv add forbiddenfruit

poetry

poetry add forbiddenfruit

Installing 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

License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)License :: OSI Approved :: MIT License

Tags

monkey patch built-in typesextend int str list methodsadd methods to built-in classesruntime built-in type modificationcurse reverse built-in objectsdynamic method injection pythonpatch immutable types
metaprogrammingc-extensiontesting-utilities

More Software Development packages