Skip to content

henu-wang/keeprule-pypi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

keeprule

100 curated investment principles from Buffett, Munger, Graham, Lynch & more — ready to use in your Python code.

PyPI version License: MIT

Curated by KeepRule.com — the investment principles encyclopedia.

Install

pip install keeprule

Quick Start

import keeprule

# Get a random principle
p = keeprule.random()
print(f'"{p["text"]}" — {p["author"]}')

# Get all principles by Warren Buffett
buffett = keeprule.by_author("Buffett")
print(f"{len(buffett)} principles from Buffett")

# Search for "margin of safety"
results = keeprule.search("margin of safety")
for r in results:
    print(r["text"])

API Reference

keeprule.random()

Returns a random investment principle.

p = keeprule.random()
# {
#   "id": 3,
#   "text": "Price is what you pay. Value is what you get.",
#   "author": "Warren Buffett",
#   "category": "Value Investing",
#   "source": "Berkshire Hathaway Shareholder Letter, 2008"
# }

keeprule.random_multiple(count)

Returns multiple random non-repeating principles.

principles = keeprule.random_multiple(5)

keeprule.by_author(name)

Filter by author name (case-insensitive partial match).

keeprule.by_author("Munger")     # All Charlie Munger principles
keeprule.by_author("Graham")     # All Benjamin Graham principles
keeprule.by_author("Lynch")      # All Peter Lynch principles

keeprule.by_category(category)

Filter by category (case-insensitive partial match).

keeprule.by_category("Risk Management")
keeprule.by_category("Value Investing")
keeprule.by_category("Mental Models")

keeprule.search(keyword)

Full-text search across text, author, category, and source.

keeprule.search("compound")      # Principles about compound interest
keeprule.search("fear")          # Principles about fear/greed
keeprule.search("intelligent")   # The Intelligent Investor references

keeprule.all()

Returns all 100 principles.

all_principles = keeprule.all()
print(f"Total: {len(all_principles)} principles")

keeprule.authors()

Returns a sorted list of all unique author names.

keeprule.authors()
# ["Albert Einstein", "Alexander Elder", "Benjamin Graham", "Charlie Munger", ...]

keeprule.categories()

Returns a sorted list of all unique categories.

keeprule.categories()
# ["Behavioral Finance", "Business Quality", "Circle of Competence", ...]

keeprule.get_by_id(id)

Get a specific principle by its ID (1-100).

p = keeprule.get_by_id(1)
# Rule No. 1: Never lose money...

keeprule.count()

Returns the total number of principles.

keeprule.count()  # 100

Data Structure

Each principle is a dict with:

Key Type Description
id int Unique identifier (1-100)
text str The investment principle or quote
author str Author name
category str Category classification
source str Source reference

Categories

  • Value Investing — Core value investing principles
  • Risk Management — Managing and understanding risk
  • Market Psychology — Understanding market behavior
  • Long-term Investing — Patience and compound growth
  • Mental Models — Thinking frameworks
  • Behavioral Finance — Psychology of investing
  • Circle of Competence — Knowing your limits
  • Decision Making — Better investment decisions
  • Business Quality — Evaluating businesses
  • Financial Discipline — Spending, saving, discipline
  • Portfolio Management — Diversification and allocation
  • Research — Due diligence and analysis

Featured Authors

  • Warren Buffett — The Oracle of Omaha
  • Charlie Munger — Berkshire Hathaway Vice Chairman
  • Benjamin Graham — Father of Value Investing
  • Peter Lynch — Legendary Fidelity fund manager
  • John Templeton — Global investing pioneer
  • John Bogle — Vanguard founder, index fund advocate
  • Jesse Livermore — Legendary stock trader
  • Philip Fisher — Growth investing pioneer
  • George Soros — Quantum Fund founder

Use Cases

  • Daily principle bot — Display a random principle every day
  • Financial apps — Enrich your app with curated wisdom
  • CLI tools — Show investing tips in terminal
  • Education — Teach investment principles programmatically
  • Data analysis — Analyze investing wisdom patterns

Explore More

Visit KeepRule.com for:

  • Interactive investment principle scenarios
  • Deep-dive explanations with real-world examples
  • AI-powered investment principle analysis
  • Community discussions and notes

License

MIT - see LICENSE

Contributing

Issues and PRs welcome at GitHub.

🔗 More KeepRule Resources

Free Tools

For Developers

Learning


Built by William Wang | All Tools

Releases

No releases published

Packages

 
 
 

Contributors

Languages