Skip to main content

Generate client libraries from prompts.

Project description

PromptSDK

PromptSDK is a CLI tool for generating client code with appropriate type signature from a folder containing prompts in Markdown format.

Installation

uv add prompt-sdk

uv run prompt-sdk --help

Explanation

Prompts are often written in Markdown and can get quite long. Writing them directly into your Python function has some disadvantages. It has no syntax highlighting and also bloats up the Python source file.

def format_prompt(doc_texts: str, doc_types_definitions: str):
    return """# Input

The following documents have been uploaded:

{doc_texts}

# Your task

Classify each page in each document into zero or one of the following document types, based on their content:

{doc_types_definitions}
""".format(doc_texts=doc_texts, doc_types_definitions=doc_types_definitions)

agent.run(format_prompt(...))

A naive solution would be to write the system prompt in an external Markdown file and read it in the Python code.

# Input

The following documents have been uploaded:

{doc_texts}

# Your task

Classify each page in each document into zero or one of the following document types, based on their content:

{doc_types_definitions}
prompt_path = PROMPTS_DIR / "classifier.md"
prompt = prompt_path.read_text()

agent.run(prompt.format(...))

The problem is that you need to inspect the Markdown file to know which variables are used in the prompt. PromptSDK solves this by generating client code from a prompts folder.

ls prompts
# info_extractor.md  classifier.md

uv run promptsdk --input prompts --output generated_sdk.py --name SDK
from .generated_sdk import SDK

agent.run(SDK.classifier(...))

Prompt Templates

PromptSDK uses jinja to read the templates.

---
name: "classifier"
description: "The text here appears as a docstring in the generated Python code."
---
# Example

PromptSDK finds variables that are enclosed in two curly braces. 
The type of the generated function argument is a String.

{{ example }}

Configuration

PromptSDK looks at pyproject.toml for configuration options. When not given it looks at the CLI flags.

# pyproject.toml

[tool.prompt-sdk]
input_path = "templates"
output_path = "generated_sdk.py"
use_class = true
class_name = "SDK"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prompt_sdk_python-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prompt_sdk_python-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file prompt_sdk_python-0.1.0.tar.gz.

File metadata

  • Download URL: prompt_sdk_python-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for prompt_sdk_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 da33648c2c4da14dfec0672b19769212c491c8a13a854254ba7aaa1467bd5058
MD5 b4475c9a5b48621e991b5c69cd406f4d
BLAKE2b-256 d5e2d7126d7de083a1cea6406ec816622b081a098494ddeb6a574f8031ee72af

See more details on using hashes here.

File details

Details for the file prompt_sdk_python-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: prompt_sdk_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for prompt_sdk_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bcdb792d1df8733505138930cce1d00e1a342885b92ef316b8abeb94e70f0358
MD5 5a6d44aa9bdd65e6c8abfe500d678862
BLAKE2b-256 933270fbcaa48f28f4b2c01d7737d925db8b8558e7f20d1ccac5a93c60675a8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page