Prompt Oriented Programming (POP): reusable, composable prompt functions for LLMs.
Project description
Prompt Oriented Programming (POP)
from POP import PromptFunction
pf = PromptFunction(
prompt="Draw a simple ASCII art of <<<object>>>.",
client = "openai"
)
print(pf.execute(object="a cat"))
print(pf.execute(object="a rocket"))
/\_/\
( o.o )
> ^ <
/\
/ \
/ \
| |
| |
Reusable, composable prompt functions for LLM workflows.
This release cleans the architecture, moves all LLM client logic to a separate LLMClient module, and extends multi-LLM backend support.
PyPI: https://pypi.org/project/pop-python/
GitHub: https://github.com/sgt1796/POP
Table of Contents
-
- Placeholders
- Reserved Keywords
- Executing prompts
- Improving prompts
1. Overview
Prompt Oriented Programming (POP) is a lightweight framework for building reusable, parameterized prompt functions. Instead of scattering prompt strings across your codebase, POP lets you:
- encapsulate prompts as objects
- pass parameters cleanly via placeholders
- select a backend LLM client dynamically
- improve prompts using meta-prompting
- generate OpenAI-compatible function schemas
- use unified embedding tools
- work with multiple LLM providers through
LLMClientsubclasses
POP is designed to be simple, extensible, and production-friendly.
2. Major Updates
This version introduces structural and functional improvements:
2.1. LLMClient moved into its own module
LLMClient.py now holds all LLM backends:
- OpenAI
- Gemini
- Deepseek
- Doubao
- Local PyTorch stub
- Extensible architecture for adding new backends
2.2. Expanded multi-LLM support
Each backend now has consistent interface behavior and multimodal (text + image) support where applicable.
3. Features
-
Reusable Prompt Functions Use
<<<placeholder>>>syntax to inject dynamic content. -
Multi-LLM Backend Choose between OpenAI, Gemini, Deepseek, Doubao, or local models.
-
Prompt Improvement Improve or rewrite prompts using Fabric-style metaprompts.
-
Function Schema Generation Convert natural language descriptions into OpenAI-function schemas.
-
Unified Embedding Interface Supports OpenAI, Jina AI embeddings, and local HuggingFace models.
-
Webpage Snapshot Utility Convert any URL into structured text using r.jina.ai with optional image captioning.
4. Installation
Install from PyPI:
pip install pop-python
Or install in development mode from GitHub:
git clone https://github.com/sgt1796/POP.git
cd POP
pip install -e .
5. Setup
Create a .env file in your project root:
OPENAI_API_KEY=your_openai_key
GEMINI_API_KEY=your_gcp_gemini_key
DEEPSEEK_API_KEY=your_deepseek_key
DOUBAO_API_KEY=your_volcengine_key
JINAAI_API_KEY=your_jina_key
All clients automatically read keys from environment variables.
6. PromptFunction
The core abstraction of POP is the PromptFunction class.
from POP import PromptFunction
pf = PromptFunction(
sys_prompt="You are a helpful AI.",
prompt="Give me a summary about <<<topic>>>."
)
print(pf.execute(topic="quantum biology"))
6.1. Placeholder Syntax
Use angle-triple-brackets inside your prompt:
<<<placeholder>>>
These are replaced at execution time.
Example:
prompt = "Translate <<<sentence>>> to French."
6.2. Reserved Keywords
Within .execute(), the following keyword arguments are reserved and should not be used as placeholder names:
modelsysfmttoolstempimagesADD_BEFOREADD_AFTER
Most keywords are used for parameters. ADD_BEFORE and ADD_AFTER will attach input string to head/tail of the prompt.
6.3. Executing prompts
result = pf.execute(
topic="photosynthesis",
model="gpt-4o-mini",
temp=0.3
)
6.4. Improving Prompts
You can ask POP to rewrite or enhance your system prompt:
better = pf._improve_prompt()
print(better)
This uses a Fabric-inspired meta-prompt bundled in the prompts/ directory.
7. Function Schema Generation
POP supports generating OpenAI function-calling schemas from natural language descriptions.
schema = pf.generate_schema(
description="Return the square and cube of a given integer."
)
print(schema)
What this does:
- Applies a standard meta-prompt
- Uses the selected LLM backend
- Produces a valid JSON Schema for OpenAI function calling
- Optionally saves it under
functions/
8. Embeddings
POP includes a unified embedding interface:
from POP.Embedder import Embedder
embedder = Embedder(use_api="openai")
vecs = embedder.get_embedding(["hello world"])
Supported modes:
- OpenAI embeddings
- JinaAI embeddings
- Local HuggingFace model embeddings (cpu/gpu)
Large inputs are chunked automatically when needed.
9. Web Snapshot Utility
from POP import get_text_snapshot
text = get_text_snapshot("https://example.com", image_caption=True)
print(text[:500])
Supports:
- optional image removal
- optional image captioning
- DOM selector filtering
- returning JSON or plain text
10. Examples
from POP import PromptFunction
pf = PromptFunction(prompt="Give me 3 creative names for a <<<thing>>>.")
print(pf.execute(thing="robot"))
print(pf.execute(thing="new language"))
11. Contributing
Steps:
- Fork the GitHub repo
- Create a feature branch
- Add tests or examples
- Submit a PR with a clear explanation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pop_python-1.0.0.tar.gz.
File metadata
- Download URL: pop_python-1.0.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8ba02b8af3198176b9922f042f35470cb46735ab96de7e42097d4dfb73e128d
|
|
| MD5 |
2b36fca3a48b66c053f0d2fa3fea3dff
|
|
| BLAKE2b-256 |
86d9d62a0d09573bca8aa22549920e1cf7e6d3c12d5f4f0596241f0cdb6910a2
|
Provenance
The following attestation bundles were made for pop_python-1.0.0.tar.gz:
Publisher:
publish-pypi.yaml on sgt1796/POP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pop_python-1.0.0.tar.gz -
Subject digest:
f8ba02b8af3198176b9922f042f35470cb46735ab96de7e42097d4dfb73e128d - Sigstore transparency entry: 707758762
- Sigstore integration time:
-
Permalink:
sgt1796/POP@decf5112a0c66e3094a3834ca766b89fc05b79fe -
Branch / Tag:
refs/tags/pop-python-v1.0.1 - Owner: https://github.com/sgt1796
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yaml@decf5112a0c66e3094a3834ca766b89fc05b79fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file pop_python-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pop_python-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ece85ebf5d047acc2759be5c35f597c5982eab4876f150a2798b26ca96f51ac
|
|
| MD5 |
e9275caacb5dfc9f83e5325c2232fa74
|
|
| BLAKE2b-256 |
2f7ca9930fc73b4a1adf231dea8a1c2725eff67e9209f56d3fcccd786710006f
|
Provenance
The following attestation bundles were made for pop_python-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yaml on sgt1796/POP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pop_python-1.0.0-py3-none-any.whl -
Subject digest:
2ece85ebf5d047acc2759be5c35f597c5982eab4876f150a2798b26ca96f51ac - Sigstore transparency entry: 707758765
- Sigstore integration time:
-
Permalink:
sgt1796/POP@decf5112a0c66e3094a3834ca766b89fc05b79fe -
Branch / Tag:
refs/tags/pop-python-v1.0.1 - Owner: https://github.com/sgt1796
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yaml@decf5112a0c66e3094a3834ca766b89fc05b79fe -
Trigger Event:
push
-
Statement type: