contexting
Template-based prompt assembly. Fill {{slot}} placeholders in a base prompt using ordered injectors and a runtime context.
Installation
pip install contexting
How it works
- Inline injection — if a slot exists in the template, the injector's output replaces it directly
- Appended injection — if the slot is absent, the output is collected and appended after the filled template, separated by a blank line
- Base fill — after all injectors run, remaining
{{slots}}are filled directly from context (strings and numbers only)
API
from contexting import assemble, create_injector
create_injector(slot, fn)
| param | type | description |
|---|---|---|
slot |
str |
name matching {{slot}} in the template |
fn |
Callable[[dict], str] |
receives the full context, returns the string to inject |
assemble(base_prompt, rules, context)
| param | type | description |
|---|---|---|
base_prompt |
str |
template string with {{slot}} placeholders |
rules |
list[Injector] |
ordered injectors applied before base fill |
context |
dict |
passed to every injector fn; also fills remaining slots |
Returns the assembled str.
Examples
Inline and appended injection
from contexting import assemble, create_injector
base_prompt = 'You are a {{role}} assistant for the language {{lang}}.'
# Inline — {{role}} exists in template, replaced directly
role_injector = create_injector('role', lambda ctx:
'senior software engineer' if ctx.get('senior') else 'helpful coding'
)
# Appended — {{constraints}} absent, output appended after a blank line
constraints_injector = create_injector('constraints', lambda ctx:
'Never suggest running untrusted code. Always explain risks.' if ctx.get('safe') else ''
)
lang_injector = create_injector('lang', lambda ctx:
'javascript, node and typescript' if ctx.get('lang') == 'javascript' else 'python and java'
)
prompt = assemble(base_prompt, [role_injector, constraints_injector, lang_injector], {
'senior': True,
'safe': True,
'lang': 'javascript',
})
print(prompt)
# You are a senior software engineer assistant for the language javascript, node and typescript.
#
# Never suggest running untrusted code. Always explain risks.
Base fill from context
Remaining slots not handled by any injector are filled directly from context:
prompt = assemble('Hello {{name}}, you are using {{lang}}.', [], {
'name': 'Alice',
'lang': 'python',
})
print(prompt)
# Hello Alice, you are using python.
Language-aware prompts
base_prompt = '{{lang_style}} Help the user with their question about {{topic}}.'
lang_style = create_injector('lang_style', lambda ctx: {
'es': 'Respond only in Spanish. Be warm and conversational.',
'fr': 'Respond only in French. Be formal and precise.',
}.get(ctx.get('lang'), 'Respond in English. Be clear and concise.'))
prompt = assemble(base_prompt, [lang_style], {'lang': 'es', 'topic': 'cooking'})
print(prompt)
# Respond only in Spanish. Be warm and conversational. Help the user with their question about cooking.
Metadata
Release files for contexting 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| contexting-0.1.1-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details for contexting-0.1.1-cp38-abi3-win_amd64.whl |
| contexting-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ x86-64 | Details for contexting-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| contexting-0.1.1-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details for contexting-0.1.1-cp38-abi3-macosx_11_0_arm64.whl |
Total release size: 1.9 MB
Release files / contexting-0.1.1-cp38-abi3-win_amd64.whl
| Download URL | contexting-0.1.1-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 598.6 kB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
fbb5129c10b9275be2c3d4dee66d63e63a1257eb628084f1d5f422880a3317d6
|
|
BLAKE2b-256 checksum How to use checksums |
50a38b17ba88ca38f66db6f77a7f3dd44fbe1f8e5868c692f10f72cb24e086fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 22, 2026.
Transparency logRelease files / contexting-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | contexting-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 684.7 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7c9452716c2546798ed6cde53e19ad34bdbe704589d328bb991c4799e054f92b
|
|
BLAKE2b-256 checksum How to use checksums |
9d613fd4f33c56033bdde5d02a9f9102a0ec46d3db5d8debff4bee4cee887746
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 22, 2026.
Transparency logRelease files / contexting-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | contexting-0.1.1-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 616.5 kB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b4248c4878cc78ccb430dae59d94373ed53eefaffe186088a8426be0e1b202f9
|
|
BLAKE2b-256 checksum How to use checksums |
6d3dcc1bc4cc0ebdab002aefa7d6cb80650e01edff825ba8d57a8140ca9f4ece
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 22, 2026.
Transparency logSecurity for contexting 0.1.1
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.
Full provenance
All 3 files in this release have been uploaded with provenance metadata.
Attestation for contexting-0.1.1-cp38-abi3-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 22, 2026.
Transparency logA 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.