Skip to main content

Python f Codec

Wrap lonesome f-strings in print().

How to install

> python3 -m pip install f-codec

Why?

# -*- coding: f -*-

def dictionary(inst, depth=0):
    ಠ_ಠ = '    ' * depth

    f''' {{
'''

    for name, val in inst.items():
        if isinstance(val, dict):
            f'''
    {name} =
''' > ಠ_ಠ
            dictionary(val, depth + 1)
        else:
            f'''
    {name} = {val},
''' > ಠ_ಠ

    f'''
}}
''' > ಠ_ಠ

decl = {
    'a': 1,
    'b': 2,
    'c': { 'a': 3, 'b': 4 },
    'd': { 'a': 5, 'b': { 'a': 6, 'b': 7 }, 'c': 8 },
    'e': 9
}

f'''
decl =
'''
dictionary(decl)
> python3 test.py

decl = {
    a = 1,
    b = 2,
    c = {
        a = 3,
        b = 4,
    }
    d = {
        a = 5,
        b = {
            a = 6,
            b = 7,
        }
        c = 8,
    }
    e = 9,
}

Development

> python3 -m unittest test_fcodec -v  # run the regression suite
> uv build                            # build sdist and wheel into dist/

The test suite compares decoding against golden files in tests/golden/, which lock in the exact transformation of known-good sources.

TODO

  • true streaming support for IncrementalDecoder (currently it buffers the whole input and decodes at once)
  • skip f-string if the previous line ends with "" and it isn't a comment
  • skip f-string inside another string
  • support for ''' > indent on a single-line f-string (only whitespace or a comment may follow the closing quotes)
  • support for triple-quoted strings inside an ''' > indent expression
  • preserve CRLF line endings (currently normalized to LF)

Metadata

Release files for f-codec 0.1.2

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

Source distribution (sdist)

Source distribution for f-codec 0.1.2
File Size Uploaded
f_codec-0.1.2.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for f-codec 0.1.2
File Interpreter ABI Platform
f_codec-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / f_codec-0.1.2.tar.gz

Download URL f_codec-0.1.2.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
216bec50e3b99b217d3d1dbeb22b7b8cab20f3d9663a3e9735c1a133961a440f
BLAKE2b-256 checksum
How to use checksums
3367ec3a8696d8919bec94931782d92d811e41804350fed50d778d117a440b4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / f_codec-0.1.2-py3-none-any.whl

Download URL f_codec-0.1.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7e779e1b4be5d54db72e0591219a062b5c8f02c14b498967c003563774b242d
BLAKE2b-256 checksum
How to use checksums
c2fb24045702d96a454b1209ee6a525a41ddea9263e8b22aaa9a191823bf4da1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

1 release file

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

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