--- id: forbiddenfruit version: "0.1.4" license: unclear license_treatment: unclear maintenance: active --- # forbiddenfruit — Patch python built-in objects License: unclear · Maintenance: active · Downloads: 2.5M/mo ## 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 above — 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 pip install forbiddenfruit uv add forbiddenfruit 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: unspecified - Install friction: high - Maintenance: active - Downloads: 2.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags monkey patch built-in types, extend int str list methods, add methods to built-in classes, runtime built-in type modification, curse reverse built-in objects, dynamic method injection python, patch immutable types, metaprogramming, c-extension, testing-utilities [View on SkillFed](https://skillfed.io/packages/forbiddenfruit) · [View on PyPI](https://pypi.org/project/forbiddenfruit/)