Skip to main content

FStringInterpolation - interpolation configparser that does f-string substitution

Extended Interpolation for the normal Python configparser

  • Apply f-string interpolation on values.

Usage

>>> import configparser
>>> from fstringinterpolation import FStringInterpolation
>>> config = configparser.ConfigParser(interpolation=FStringInterpolation())
>>> config.read_string("""
[DEFAULT]
_pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286
[full]
pi = {_pi}
[short]
pi = {float(_pi):.2f}
[stringy]
pi = {_pi:.2s}
""")
>>> config["full"]["pi"]
'3.141592653589793238462643383279502884197169399375105820974944592307816406286'
>>> config["short"]["pi"]
'3.14'
>>> config["stringy"]["pi"]
'3.'

More examples

This will automatically create the proper title, depending on the values of a and b

Input

[DEFAULT]
a = 7
title = {a} is {"more" if float(a) > float(b) else "less"} than {b}
[A]
b = 12
[B]
b = 3
[C]
a = 3.14
b = 2.71

Output

section title
A "7 is less than 12"
B "7 is more than 3"
C "3.14 is more than 2.71"

Installing

TODO

Building

python3 -m build

Caveats

  • no recursion! e.g. the following is invalid:

    [DEFAULT]
    pi = 3.141592654
    [int]
    pi = {float(pi)}
    
  • the type of each value is always . if you need something else, you must explicitely convert the values:

    [DEFAULT]
    pi = 3.141592654
    [bad]
    halfpi = {pi/2}
    [good]
    halfpi = {float(pi)/2}
    
  • care must be taken to not override python built-ins (that you want to use) with variables:

    [DEFAULT]
    a = 10
    b = 12
    [good]
    realsum = {sum(float(_) for _ in [a,b])}
    [bad]
    realsum = {sum(float(_) for _ in [a,b])}
    sum = 22
    [bad recursion]
    sum = {sum(float(_) for _ in [a,b])}
    
  • currently, recursion is somewhat broken (unless the interpolated values are re-used as strings):

    [test]
    a = 3
    # b becomes '4'
    b = {int(a)+1}
    # GOOD: c becomes '34' ('3'+'4')
    c = {a+b}
    # BAD: d should become 7, but really fails with "int('{int(a)+1)}')"
    d = {int(a)+int(b)}
    

Metadata

Release files for FStringInterpolation 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for FStringInterpolation 0.2.0
File Size Uploaded Provenance Actions
fstringinterpolation-0.2.0.tar.gz 5.9 kB With provenance Details for fstringinterpolation-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for FStringInterpolation 0.2.0
File Interpreter ABI Platform Actions
fstringinterpolation-0.2.0-py3-none-any.whl Python 3 none any Details for fstringinterpolation-0.2.0-py3-none-any.whl

Total release size: 10.8 kB

Release files / fstringinterpolation-0.2.0.tar.gz

Download URL fstringinterpolation-0.2.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
96551d065792d534a1feeb7b979010b44c65ada24d093b2d44f0a2728784314f
BLAKE2b-256 checksum
How to use checksums
b970007ccff3cc04de97f407691ef71aa23817c30d77271d1c3098d2fec422e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 25, 2025.

Transparency log

Release files / fstringinterpolation-0.2.0-py3-none-any.whl

Download URL fstringinterpolation-0.2.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec793ebe46b99c3fe01eaca0d75237aea8266ba596da519dc352d082636f6a9e
BLAKE2b-256 checksum
How to use checksums
0694e07e9d952bc4bb6738b111317b652fad0e8056f8935d2360ff4d49e98fa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 25, 2025.

Transparency log

Security for FStringInterpolation 0.2.0

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 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fstringinterpolation-0.2.0.tar.gz

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 Aug 25, 2025.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page