textprompts 0.0.3__tar.gz → 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: textprompts
3
- Version: 0.0.3
3
+ Version: 1.0
4
4
  Summary: Minimal text-based prompt-loader with TOML front-matter
5
5
  Keywords: prompts,toml,frontmatter,template
6
6
  Author: Jan Siml
@@ -33,7 +33,7 @@ Description-Content-Type: text/markdown
33
33
 
34
34
  > **So simple, it's not even worth vibing about coding yet it just makes so much sense.**
35
35
 
36
- Are you tired of vendors trying to sell you fancy UIs for prompt management that just make your system more confusing and harder to debug? Isn't it nice to just have your prompts **next to your code**?
36
+ Are you tired of vendors trying to sell you fancy UIs for prompt management that just make your system more confusing and harder to debug? Isn't it nice to just have your prompts **next to your code**?
37
37
 
38
38
  But then you worry: *Did my formatter change my prompt? Are those spaces at the beginning actually part of the prompt or just indentation?*
39
39
 
@@ -42,7 +42,7 @@ But then you worry: *Did my formatter change my prompt? Are those spaces at the
42
42
  ## Why textprompts?
43
43
 
44
44
  - ✅ **Prompts live next to your code** - no external systems to manage
45
- - ✅ **Git is your version control** - diff, branch, and experiment with ease
45
+ - ✅ **Git is your version control** - diff, branch, and experiment with ease
46
46
  - ✅ **No formatter headaches** - your prompts stay exactly as you wrote them
47
47
  - ✅ **Minimal markup** - just TOML front-matter when you need metadata (or no metadata if you prefer!)
48
48
  - ✅ **Zero dependencies** - well, almost (just Pydantic)
@@ -81,12 +81,12 @@ import textprompts
81
81
  # Just load it - works with or without metadata
82
82
  prompt = textprompts.load_prompt("greeting.txt")
83
83
  # Or simply
84
- alt = textprompts.Prompt("greeting.txt")
84
+ alt = textprompts.Prompt.from_path("greeting.txt")
85
85
 
86
86
  # Use it safely - all placeholders must be provided
87
87
  message = prompt.prompt.format(
88
88
  customer_name="Alice",
89
- company_name="ACME Corp",
89
+ company_name="ACME Corp",
90
90
  issue_type="billing question",
91
91
  agent_name="Sarah"
92
92
  )
@@ -169,7 +169,7 @@ prompt = textprompts.load_prompt("prompt.txt") # No metadata parsing
169
169
  print(prompt.meta.title) # "prompt" (from filename)
170
170
 
171
171
  # 2. ALLOW: Load metadata if present, don't worry if it's incomplete
172
- textprompts.set_metadata("allow") # Flexible metadata loading
172
+ textprompts.set_metadata("allow") # Flexible metadata loading
173
173
  prompt = textprompts.load_prompt("prompt.txt") # Loads any metadata found
174
174
 
175
175
  # 3. STRICT: Require complete metadata for production use
@@ -182,7 +182,7 @@ prompt = textprompts.load_prompt("prompt.txt", meta="strict")
182
182
 
183
183
  **Why this design?**
184
184
  - **Default = Simple**: No configuration needed, just load files
185
- - **Flexible**: Add metadata when you want structure
185
+ - **Flexible**: Add metadata when you want structure
186
186
  - **Production-Safe**: Use strict mode to catch missing metadata before deployment
187
187
 
188
188
  ## Real-World Examples
@@ -207,7 +207,7 @@ response = openai.chat.completions.create(
207
207
  )
208
208
  },
209
209
  {
210
- "role": "user",
210
+ "role": "user",
211
211
  "content": user_prompt.prompt.format(
212
212
  query="How do I return an item?",
213
213
  customer_tier="premium"
@@ -241,7 +241,7 @@ description = "Search our product catalog"
241
241
  "description": "Search query for products"
242
242
  },
243
243
  "category": {
244
- "type": "string",
244
+ "type": "string",
245
245
  "enum": ["electronics", "clothing", "books"],
246
246
  "description": "Product category to search within"
247
247
  },
@@ -323,7 +323,7 @@ Use {variables} for templating.
323
323
  Choose the right level of strictness for your use case:
324
324
 
325
325
  1. **IGNORE** (default) - Simple text file loading, filename becomes title
326
- 2. **ALLOW** - Load metadata if present, don't worry about completeness
326
+ 2. **ALLOW** - Load metadata if present, don't worry about completeness
327
327
  3. **STRICT** - Require complete metadata (title, description, version) for production safety
328
328
 
329
329
  You can also set the environment variable `TEXTPROMPTS_METADATA_MODE` to one of
@@ -333,7 +333,7 @@ default mode.
333
333
  ```python
334
334
  # Set globally
335
335
  textprompts.set_metadata("ignore") # Default: simple file loading
336
- textprompts.set_metadata("allow") # Flexible: load any metadata
336
+ textprompts.set_metadata("allow") # Flexible: load any metadata
337
337
  textprompts.set_metadata("strict") # Production: require complete metadata
338
338
 
339
339
  # Or override per prompt
@@ -411,7 +411,7 @@ template = PromptString("Hello {name}, you are {role}")
411
411
  result = template.format(name="Alice", role="admin") # ✅ Works
412
412
  result = template.format(name="Alice") # ❌ Raises ValueError
413
413
 
414
- # Partial formatting - replace only available placeholders
414
+ # Partial formatting - replace only available placeholders
415
415
  partial = template.format(name="Alice", skip_validation=True) # ✅ "Hello Alice, you are {role}"
416
416
 
417
417
  # Access placeholder information
@@ -503,4 +503,4 @@ MIT License - see [LICENSE](LICENSE) for details.
503
503
 
504
504
  ---
505
505
 
506
- **textprompts** - Because your prompts deserve better than being buried in code strings. 🚀
506
+ **textprompts** - Because your prompts deserve better than being buried in code strings. 🚀
@@ -9,7 +9,7 @@
9
9
 
10
10
  > **So simple, it's not even worth vibing about coding yet it just makes so much sense.**
11
11
 
12
- Are you tired of vendors trying to sell you fancy UIs for prompt management that just make your system more confusing and harder to debug? Isn't it nice to just have your prompts **next to your code**?
12
+ Are you tired of vendors trying to sell you fancy UIs for prompt management that just make your system more confusing and harder to debug? Isn't it nice to just have your prompts **next to your code**?
13
13
 
14
14
  But then you worry: *Did my formatter change my prompt? Are those spaces at the beginning actually part of the prompt or just indentation?*
15
15
 
@@ -18,7 +18,7 @@ But then you worry: *Did my formatter change my prompt? Are those spaces at the
18
18
  ## Why textprompts?
19
19
 
20
20
  - ✅ **Prompts live next to your code** - no external systems to manage
21
- - ✅ **Git is your version control** - diff, branch, and experiment with ease
21
+ - ✅ **Git is your version control** - diff, branch, and experiment with ease
22
22
  - ✅ **No formatter headaches** - your prompts stay exactly as you wrote them
23
23
  - ✅ **Minimal markup** - just TOML front-matter when you need metadata (or no metadata if you prefer!)
24
24
  - ✅ **Zero dependencies** - well, almost (just Pydantic)
@@ -57,12 +57,12 @@ import textprompts
57
57
  # Just load it - works with or without metadata
58
58
  prompt = textprompts.load_prompt("greeting.txt")
59
59
  # Or simply
60
- alt = textprompts.Prompt("greeting.txt")
60
+ alt = textprompts.Prompt.from_path("greeting.txt")
61
61
 
62
62
  # Use it safely - all placeholders must be provided
63
63
  message = prompt.prompt.format(
64
64
  customer_name="Alice",
65
- company_name="ACME Corp",
65
+ company_name="ACME Corp",
66
66
  issue_type="billing question",
67
67
  agent_name="Sarah"
68
68
  )
@@ -145,7 +145,7 @@ prompt = textprompts.load_prompt("prompt.txt") # No metadata parsing
145
145
  print(prompt.meta.title) # "prompt" (from filename)
146
146
 
147
147
  # 2. ALLOW: Load metadata if present, don't worry if it's incomplete
148
- textprompts.set_metadata("allow") # Flexible metadata loading
148
+ textprompts.set_metadata("allow") # Flexible metadata loading
149
149
  prompt = textprompts.load_prompt("prompt.txt") # Loads any metadata found
150
150
 
151
151
  # 3. STRICT: Require complete metadata for production use
@@ -158,7 +158,7 @@ prompt = textprompts.load_prompt("prompt.txt", meta="strict")
158
158
 
159
159
  **Why this design?**
160
160
  - **Default = Simple**: No configuration needed, just load files
161
- - **Flexible**: Add metadata when you want structure
161
+ - **Flexible**: Add metadata when you want structure
162
162
  - **Production-Safe**: Use strict mode to catch missing metadata before deployment
163
163
 
164
164
  ## Real-World Examples
@@ -183,7 +183,7 @@ response = openai.chat.completions.create(
183
183
  )
184
184
  },
185
185
  {
186
- "role": "user",
186
+ "role": "user",
187
187
  "content": user_prompt.prompt.format(
188
188
  query="How do I return an item?",
189
189
  customer_tier="premium"
@@ -217,7 +217,7 @@ description = "Search our product catalog"
217
217
  "description": "Search query for products"
218
218
  },
219
219
  "category": {
220
- "type": "string",
220
+ "type": "string",
221
221
  "enum": ["electronics", "clothing", "books"],
222
222
  "description": "Product category to search within"
223
223
  },
@@ -299,7 +299,7 @@ Use {variables} for templating.
299
299
  Choose the right level of strictness for your use case:
300
300
 
301
301
  1. **IGNORE** (default) - Simple text file loading, filename becomes title
302
- 2. **ALLOW** - Load metadata if present, don't worry about completeness
302
+ 2. **ALLOW** - Load metadata if present, don't worry about completeness
303
303
  3. **STRICT** - Require complete metadata (title, description, version) for production safety
304
304
 
305
305
  You can also set the environment variable `TEXTPROMPTS_METADATA_MODE` to one of
@@ -309,7 +309,7 @@ default mode.
309
309
  ```python
310
310
  # Set globally
311
311
  textprompts.set_metadata("ignore") # Default: simple file loading
312
- textprompts.set_metadata("allow") # Flexible: load any metadata
312
+ textprompts.set_metadata("allow") # Flexible: load any metadata
313
313
  textprompts.set_metadata("strict") # Production: require complete metadata
314
314
 
315
315
  # Or override per prompt
@@ -387,7 +387,7 @@ template = PromptString("Hello {name}, you are {role}")
387
387
  result = template.format(name="Alice", role="admin") # ✅ Works
388
388
  result = template.format(name="Alice") # ❌ Raises ValueError
389
389
 
390
- # Partial formatting - replace only available placeholders
390
+ # Partial formatting - replace only available placeholders
391
391
  partial = template.format(name="Alice", skip_validation=True) # ✅ "Hello Alice, you are {role}"
392
392
 
393
393
  # Access placeholder information
@@ -479,4 +479,4 @@ MIT License - see [LICENSE](LICENSE) for details.
479
479
 
480
480
  ---
481
481
 
482
- **textprompts** - Because your prompts deserve better than being buried in code strings. 🚀
482
+ **textprompts** - Because your prompts deserve better than being buried in code strings. 🚀
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "textprompts"
3
- version = "0.0.3"
3
+ version = "1.0"
4
4
  description = "Minimal text-based prompt-loader with TOML front-matter"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -60,6 +60,7 @@ ignore = ["E501"] # Ignore line length
60
60
  [tool.mypy]
61
61
  python_version = "3.11"
62
62
  strict = true
63
+ mypy_path = "src"
63
64
 
64
65
  [tool.pytest.ini_options]
65
66
  testpaths = ["tests"]
@@ -21,22 +21,14 @@ class Prompt(BaseModel):
21
21
  meta: Union[PromptMeta, None]
22
22
  prompt: PromptString
23
23
 
24
- def __init__(
25
- self,
26
- path: Union[str, Path],
27
- meta: Union[PromptMeta, MetadataMode, str, None] = None,
28
- prompt: Union[str, PromptString, None] = None,
29
- ) -> None:
30
- """Initialize Prompt from fields or load from file."""
31
- if prompt is None:
32
- from .loaders import load_prompt
33
-
34
- loaded = load_prompt(path, meta=meta)
35
- super().__init__(**loaded.model_dump())
36
- else:
37
- if isinstance(prompt, str):
38
- prompt = PromptString(prompt)
39
- super().__init__(path=Path(path), meta=meta, prompt=prompt)
24
+ @classmethod
25
+ def from_path(
26
+ cls, path: Union[str, Path], *, meta: Union[MetadataMode, str, None] = None
27
+ ) -> "Prompt":
28
+ """Load a Prompt from ``path`` using ``load_prompt``."""
29
+ from .loaders import load_prompt
30
+
31
+ return load_prompt(path, meta=meta)
40
32
 
41
33
  @field_validator("prompt")
42
34
  @classmethod