Skip to main content

String Fixer

Simple tool to replace "double quotes" with 'single quotes' in Python files.

There are many tools out there to lint and format Python code. The most popular formatter, Black, prefers double quotes to single quotes. Ruff is a bit more flexible, but doesn't format docstrings with single quotes (it lets you skip formatting them to preserve your own quotation style).

Neither project seems likely to add the option for entirely single-quoted code, so this tool can work as a post-processor to fix that.

Usage

CLI

# run against single file
python -m string_fixer --target my_file.py
# run against directory
python -m string_fixer --target lib/src/
# run against working dir
python -m string_fixer

IDE Plugins

This project has an accompanying VSCode extension.

Configuration

Configuration is done via the pyproject.toml file and the default settings are as follows:

[tool.string-fixer]
# file or folder to format
target = "./"
# set to true to print planned changes but not modify any files (overrides `output` config)
dry_run = false
# write a copy of the files to this directory, rather than modifying them inplace
output = "./"
# list of glob patterns for files to ignore. this value is autopopulated from `.gitignore` files as well
# as a few default values. anything you put in this list will be added to this set, rather than replacing
# it. Use the `include` option to override
ignore = [
    # these are the defaults
    "./**/.*",
    "./**/site-packages",
    "./**/node_modules",
    "./**/build",
    "./**/dist",
    "./**/__pycache__",
    "./**/venv"
]
# list of glob patterns for files to include. This setting overrides `ignore`
include = []
# extend and override options in another pyproject.toml file
extends = ""
# python version to target for compatibility (defaults to current python version)
# this must be a string because `float("3.10") == 3.1`
target_version = "3.12"
# try to produce strings with the least number of escapes, even if that means deviating from the quote style
prefer_least_escapes = true
# preferred quote style. Allowed options are 'single' or "double"
quote_style = "single"

All file paths are resolved relative to the pyproject.toml's location.

See Also

Metadata

Release files for string-fixer 0.5.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 string-fixer 0.5.0
File Size Uploaded
string_fixer-0.5.0.tar.gz 11.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for string-fixer 0.5.0
File Interpreter ABI Platform
string_fixer-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.8 kB

Release files / string_fixer-0.5.0.tar.gz

Download URL string_fixer-0.5.0.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
64d3f80896dc3fe45a96530a7751fdf802382240072b346770d14433057878f3
BLAKE2b-256 checksum
How to use checksums
da5107da71e5ae3fa2f020936bd7e4696939db0838d8908726b47eacef345ade
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / string_fixer-0.5.0-py3-none-any.whl

Download URL string_fixer-0.5.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
500747ad9bc625eb8057b11bc8698f96c7fa26f2cd530b4bc18986a03ac588e2
BLAKE2b-256 checksum
How to use checksums
b5bd8082ba4049b7b7f8858598bb9b7988eca6aa77c11d7d6e66e87ab2139aa8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

1 release file

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