{"id":18669161,"url":"https://github.com/danbradham/fstrings","last_synced_at":"2025-08-22T12:36:33.723Z","repository":{"id":73672311,"uuid":"84251002","full_name":"danbradham/fstrings","owner":"danbradham","description":"f-strings...sorta","archived":false,"fork":false,"pushed_at":"2021-12-11T14:36:15.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-28T10:11:19.021Z","etag":null,"topics":["f-strings"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danbradham.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-07T22:08:03.000Z","updated_at":"2021-12-11T14:36:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"f9bf1f57-f8a8-4e49-8b24-2d1e2b0a42d3","html_url":"https://github.com/danbradham/fstrings","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danbradham%2Ffstrings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danbradham%2Ffstrings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danbradham%2Ffstrings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danbradham%2Ffstrings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danbradham","download_url":"https://codeload.github.com/danbradham/fstrings/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239499793,"owners_count":19649106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["f-strings"],"created_at":"2024-11-07T08:46:06.448Z","updated_at":"2025-02-18T15:46:04.957Z","avatar_url":"https://github.com/danbradham.png","language":"Python","readme":"=================\nf-strings...sorta\n=================\n.. image:: https://travis-ci.org/danbradham/fstrings.svg?branch=master\n    :target: https://travis-ci.org/danbradham/fstrings\n\nPython 3.6 f-strings are pretty awesome. It's too bad you can't use them in 2.7 or 3.5. With **fstrings** you can...sorta. The **fstrings** module provides a function *f* that acts similar to f-strings. Pass a string with str.format tokens and *f* will return a string formatted using the available globals and locals. Like this::\n\n    \u003e\u003e\u003e from fstrings import f\n    \u003e\u003e\u003e x = 'Hello, World...'\n    \u003e\u003e\u003e f('{x}')\n    'Hello, World...'\n\nYou can't evaluate arbitrary python code within the format tokens like you can in Python 3.6, but, some of that lost functionality is gained by allowing you to pass *args* and *kwargs* to *f*. For example, you can still use positional arguments with *f*::\n\n    \u003e\u003e\u003e x = 'World...'\n    \u003e\u003e\u003e f('{} {x}', 'Hello,')\n    'Hello, World...'\n\nOr you could override globals and locals by passing keyword arguments::\n\n    \u003e\u003e\u003e x = 'Hello'\n    \u003e\u003e\u003e y = 'World...'\n    \u003e\u003e\u003e f('{x}, {y}', x='Goodbye')\n    'Goodbye, World...'\n\nOr do both, it's your life. In addition to *f*, fstrings also provides some other nifty stuff.\n\n\nfdocstring Decorator\n====================\n::\n\n    \u003e\u003e\u003e from fstrings import fdocstring\n    \u003e\u003e\u003e x = 'Hello from ya docs'\n    \u003e\u003e\u003e @fdocstring()\n    ... def func():\n    ...     '''{x}'''\n    ...\n    \u003e\u003e\u003e func.__doc__\n    'Hello from ya docs'\n\nRight now you might be thinking, \"Cool, *fdocstring* provides the same funcality as *f*, but, for doc strings.\" You would be correct. You can even use *fdocstring* to format class doc strings:\n\n::\n\n    \u003e\u003e\u003e x = 'BOOM!'\n    \u003e\u003e\u003e @fdocstring()\n    ... class Obj(object):\n    ...     '''{x}'''\n    ...     def method(self):\n    ...         '''{x}'''\n    ...\n    \u003e\u003e\u003e Obj.__doc__\n    'BOOM!'\n    \u003e\u003e\u003e Obj.method.__doc__\n    'BOOM!'\n\n\"Boom boom\" is right. Methods are auto formatted too.\n\n\nprintf?\n=======\nAfter implementing *f*, *printf* was too obvious not to implement.\n\n::\n\n    \u003e\u003e\u003e from fstrings import printf\n    \u003e\u003e\u003e x = 'PRINTFED'\n    \u003e\u003e\u003e printf('{x}')\n    PRINTFED\n\n*printf* and *fdocstring* accept *args* and *kwargs* for overriding globals and locals just like *f*.\n\nFeatures and Differences\n========================\n\n - Uses str.format instead of evaluating python code in {}\n - Allows overriding globals and locals by passing in \\*args and \\*\\*kwargs\n - Supports python 2.7 to python 3.6\n\nTests\n=====\n**fstrings** comes with a robust set of tests. *pip install nose* and run them if you like.\n\n::\n\n    \u003e nosetests -v --with-coverage --with-doctest --doctest-extension rst\n\nSimilar Projects\n================\nIf you're looking for an implementation truer to Python 3.6 f-strings check out `fmt \u003chttps://github.com/damnever/fmt\u003e`_.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanbradham%2Ffstrings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanbradham%2Ffstrings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanbradham%2Ffstrings/lists"}