Metadata-Version: 2.1
Name: typelate
Version: 0.1.0
Summary: Python templates with type annotations and validation.
Author: Ariel Alon
License: Copyright © 2024 ArielAlon24
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project-URL: Homepage, https://github.com/ArielAlon24/typed-template
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: iniconfig >=2.0.0
Requires-Dist: packaging >=23.2
Requires-Dist: pluggy >=1.4.0
Requires-Dist: typeguard >=4.1.5
Requires-Dist: typing-extensions >=4.10.0

# typelate

Python templates with type annotations and validation.

## Background

A somewhat hidden feature in Python is the ability to create `str` templates, they are similar to f-strings but they don't require you to know the values in advance.

```python
template = "Hello, {name}!"
```

Using it is as simple as calling the `format` function

```pycon
>>> template.format(name="World")
"Hello, World!"
```

```pycon
>>> template.format(name=123)
"Hello, 123!"
```

In addition to that, like f-strings we can specify a _format specifier_ to each argument.

```python
template = "Pi is {pi: .2f}"
```

```pycon
>>> import math
>>> template.format(pi=math.pi)
"Pi is 3.14"
```

## Usage

With `typelate` this behavior is extended even more, now you can specify types for each argument in the template, in runtime a template formatting will have validation that can be handled as you wish!

```python
from typed_template import Template

template = Template("Hello, {name: str}!")
```

Notice that `Template` uses the `__call__` instead of `format`

```pycon
>>> template(name="World")
"Hello, World!"
```

Now, let's pass an invalid type.

```pycon
>>> template(name=123)
TypeError: Incorrect type for replacement 'name', expected: <class 'str'>.
```

Moreover, you can use the default format specifiers in addition to the type annotation:

```python
from typed_template import Template

template = Template("Pi is {pi: float: .2f}")
```

```pycon
>>> import math
>>> template(pi=math.pi)
"Pi is 3.14"
```
