py-priompt: Build Token-Budgeted Prompts in Python

Summary
PyPriompt is a Python library for composing LLM prompts from reusable components and selecting content by priority to fit a token limit. It suits developers who need fine-grained control over prompt contents, such as preserving recent conversation history while trimming older context.
At a glance
- Language
- Python
- License
- NOASSERTION
- Stars
- 65
- Forks
- 2
- Added to OSRepos
- November 27, 2025
- Last analyzed
- October 3, 2026
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Overview
PyPriompt is a Python port of Priompt, a prompt-design library inspired by component-based web frameworks. It lets developers build prompts as reusable Python components and uses priorities to decide which content to include when a prompt must fit a token budget.
It is most useful when prompt contents have different levels of importance, such as in long conversations or prompts assembled from files. It renders chat messages or a string, with tokenization configured for the target model.
Key Features
- Build prompts from custom components and standard system, user, and assistant message components.
- Set absolute or relative priorities for content so lower-priority sections can be omitted to meet a token limit.
- Use
Firstto provide priority-based fallbacks, andEmptyto reserve space for generation. - Add images and tool schemas to prompts with
ImageandToolscomponents. - Isolate sections with their own token limits, or force token breaks with
Br. - Capture and parse rendered output, and configure common generation properties with
Config. - Use inclusion and exclusion callbacks or source maps to inspect which prompt components were rendered.
Use Cases
- Chat application developers can keep system instructions and the latest user message while trimming older conversation history.
- AI application developers can include long files or other context selectively, favoring the most relevant sections when the token budget is tight.
- Prompt designers can reserve tokens for generated responses and provide fallback text when larger content does not fit.
- Teams debugging prompt changes can use source maps to trace rendered text back to its component, including when investigating cache misses.
Project Facts
- Language: Python
- License: NOASSERTION
- Stars: 65
- Forks: 2
- Topics: none listed
- Archived: no
Getting Started
Install the package with pip install priompt. See the README for usage examples and details.
Alternatives
- POML: POML uses markup to structure and integrate prompt content, rather than selecting reusable components by priority to fit a token limit.
Considerations
The README notes that the original test suite passes, but this port was produced in a day with AI assistance and may contain bugs. It also lists Capture, Tool, and Tools behavior and compatibility with priompt-preview as items to verify. The renderer may not always find the exact optimal priority cutoff, and performance is described as reasonable for around 10K scopes. Prompts built with many priorities can also be difficult to cache effectively.
Source repository
Open the original repository on GitHub.
16 counted GitHub visits
Related repositories
Similar repositories that may be relevant next.

web-design: Create Consistent Web Pages with a Claude Code Skill
October 3, 2026
web-design is a Claude Code skill that turns product briefs, reference URLs, or screenshots into an editable design specification before generating web code. It is suited to developers and designers who want a repeatable, spec-led workflow for building consistent pages.

oomwoo: Build a DIY Robot Vacuum
October 2, 2026
OOMWOO is a planned, hackable robot vacuum built around Raspberry Pi, ROS2 and 2D LiDAR. It is aimed at makers who want to build and customize a locally controlled vacuum, but its hardware and build instructions are still in development.

shepherd: Supervise Agents with Reversible Execution Traces
October 2, 2026
Shepherd records agent work as inspectable, reversible execution traces and keeps changes as proposals for review. It is aimed at developers building systems that supervise, replay, or manage the work of other agents.

agent-anvil: Test AI Agent Tool Use in CI
October 1, 2026
Agent Anvil evaluates tool-using AI agents through scenario-based runs, trace checks, and optional semantic grading. It helps teams catch unsafe or incorrect tool behavior before it reaches production.