Promptic – LLM superpowers for your Python functions (in ~80 lines)
Promptic – LLM superpowers for your Python functions (in ~80 lines)
Hey HN, I've been building quite a few Python services that use LLMs lately. While tools like Magentic and Marvin are great, and served as inspiration for this project, I found myself needing something simpler and more focused on my core use cases. So I created Promptic https://github.com/knowsuchagency/promptic . It's a small Python library that does one thing really well: turns your Python functions into LLM-powered wizards. How does it work? * Decorate: Add the @promptic decorator to your function. * Write a prompt: Use your function's docstring to explain what you want the LLM to do. * Get structured results: If your function returns a Pydantic model, Promptic automatically parses the LLM's response into that model. Example: ```python from promptic import promptic from pydantic import BaseModel @promptic def us_president(year): """Who was the President of the United States in {year}?""" print(us_president(2000)) # The President of the United States in 2000 was Bill Clinton until January 20th, when George W. Bush was inaugurated as the 43rd President. class Capital(BaseModel): country: str capital: str @promptic def get_capital(country) -> Capital: """What's the capital of {country}?""" print(get_capital("France")) # country='France' capital='Paris' @promptic(stream=True) def haiku(subject: str, adjective: str, verb: str) -> str: """Write a haiku about {subject} that is {adjective} and {verb}.""" print("".join(haiku("nature", "beautiful", "inspires"))) # Vibrant green leaves sway # Birds sing melodies of joy # Nature's perfect dance ``` Why use it? * Simplicity: No complex abstractions or frameworks to learn. * Focus: Promptic handles LLM interactions, you focus on your business logic. * Pydantic: Get type-safe, structured results without writing JSON parsing code. * Batteries included: Supports streaming responses and works with any LLM provider via LiteLLM. Inspired by the real world, Promptic distills the most effective patterns I've discovered while building LLM-powered services in production. It's designed for practical, everyday use cases. Feedback welcome! Let me know what you think. I'm eager to hear how Promptic fits (or doesn't) into your workflow. Happy coding!
Share cardActual performance
Launch Intel predictions
Analyze your own launch →Incorrect prediction on native model
Similar products
Hangman in 3 lines of Python
AI-assert – Constraint verification for LLM outputs (278 lines, Python)
Pongo – 80% Fewer LLM Hallucinations with one LoC
A very simple Lisp interpreter in 250 lines of literate Python
Retirement Calculator in 8 lines of Python
Querying 50k Gameservers in 100 lines of Python
A Python module to steer LLM outputs
Build python ASTs in 502 lines of python without using modules
FuzzyFinder – in 10 lines of Python
2048 in ten 60-width lines of python