Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

promptic

promptic is a lightweight, decorator-based Python library that simplifies the process of interacting with large language models (LLMs) using litellm. With promptic, you can effortlessly create prompts, handle input arguments, and receive structured outputs from LLMs with just a few lines of code.

Installation

pip install promptic

Usage

Simple Prompt

from promptic import llm

@llm
def president(year):
    """Who was the President of the United States in {year}?"""

print(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.

Structured Output with Pydantic

from pydantic import BaseModel
from promptic import llm

class Capital(BaseModel):
    country: str
    capital: str

@llm
def capital(country) -> Capital:
    """What's the capital of {country}?"""

print(capital("France"))
# country='France' capital='Paris'

Streaming Response (and litellm integration)

from promptic import llm

# most arguments are passed directly to litellm.completion
# see https://docs.litellm.ai/docs/completion

@llm(stream=True, model="claude-3-haiku-20240307")
def haiku(subject, adjective, verb="delights"):
    """Write a haiku about {subject} that is {adjective} and {verb}."""

print("".join(haiku("programming", adjective="witty")))
# Bits and bytes abound,
# Bugs and features intertwine,
# Code, the poet's rhyme.

Customize System Prompt

from promptic import llm

@llm(system="you are a snarky chatbot")
def answer(question):
    """{question}"""

print(answer("What's the best programming language?"))
# Well, that's like asking what's the best flavor of ice cream. 
# It really depends on what you're trying to accomplish and your personal preferences. 
# But if you want to start a flame war, just bring up Python vs JavaScript.

Features

  • Decorator-based API: Easily define prompts using function docstrings and decorate them with @promptic.llm.
  • Argument interpolation: Automatically interpolate function arguments into the prompt using {argument_name} placeholders within docstrings.
  • Pydantic model support: Specify the expected output structure using Pydantic models, and promptic will ensure the LLM's response conforms to the defined schema.
  • Streaming support: Receive LLM responses in real-time by setting stream=True when calling the decorated function.
  • Simplified LLM interaction: No need to remember the exact shape of the OpenAPI response object or other LLM-specific details. promptic abstracts away the complexities, allowing you to focus on defining prompts and receiving structured outputs.

Why promptic?

promptic is designed to be simple, functional, and robust, providing exactly what you need 90% of the time when working with LLMs. It eliminates the need to remember the specific shapes of OpenAPI response objects or other LLM-specific details, allowing you to focus on creating prompts and receiving structured outputs.

With its legible and concise codebase, promptic is reliable easy to understand. It leverages the power of litellm under the hood, ensuring compatibility with a wide range of LLMs.

License

promptic is open-source software licensed under the Apache License 2.0.

Metadata

Release files for promptic 0.7.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for promptic 0.7.0a1
File Size Uploaded Provenance Actions
promptic-0.7.0a1.tar.gz 8.7 kB Without provenance Details for promptic-0.7.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for promptic 0.7.0a1
File Interpreter ABI Platform Actions
promptic-0.7.0a1-py2.py3-none-any.whl Python 3, Python 2 none any Details for promptic-0.7.0a1-py2.py3-none-any.whl

Total release size: 16.3 kB

Release files / promptic-0.7.0a1.tar.gz

Download URL promptic-0.7.0a1.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ab299018fc9e54ed5aa1dd093475a74810aaa8eb732e093abc94370cc7a3af86
BLAKE2b-256 checksum
How to use checksums
43db728304ee5aac494a195b0f6b54f24a7e16d5e15907cc669b94af10de4791
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.2

Release files / promptic-0.7.0a1-py2.py3-none-any.whl

Download URL promptic-0.7.0a1-py2.py3-none-any.whl
Size 7.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e6c6f6b998037ccfb73fe193ef7343469e450403eb015a31c581b0b5717f24a4
BLAKE2b-256 checksum
How to use checksums
aab943aaf7fd621fbf551714dd8297e4f00c1e4e1ccd93b76e9db2b3bedab930
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.2

Security for promptic 0.7.0a1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page