You can use the call command that is supplied by Python to call an external command. For example, you can write a script like:

#!/usr/bin/python
import sys
from subprocess import call
lc = ["clang-format","test.c"] # replace 'test.c' with the your filename.
retcode=call(lc)
sys.exit(retcode);
Answer from ConsistentProgrammer on Stack Overflow
🌐
PyPI
pypi.org › project › clang-format
clang-format Python distribution
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Clang
clang.llvm.org › docs › ClangFormat.html
ClangFormat — Clang 23.0.0git documentation
There is an integration for vim which lets you run the clang-format standalone tool on your current buffer, optionally selecting regions to reformat. The integration has the form of a python-file which can be found under clang/tools/clang-format/clang-format.py.
🌐
GitHub
github.com › google › yapf
GitHub - google/yapf: A formatter for Python files · GitHub
YAPF is a Python formatter based on clang-format (developed by Daniel Jasper). In essence, the algorithm takes the code and calculates the best formatting that conforms to the configured style.
Starred by 14K users
Forked by 901 users
Languages   Python
🌐
LLVM
releases.llvm.org › 3.4 › tools › clang › docs › ClangFormat.html
ClangFormat — Clang 3.4 documentation
There is an integration for vim which lets you run the clang-format standalone tool on your current buffer, optionally selecting regions to reformat. The integration has the form of a python-file which can be found under clang/tools/clang-format/clang-format.py.
🌐
GitHub
github.com › Sarcasm › run-clang-format › blob › master › run-clang-format.py
run-clang-format/run-clang-format.py at master · Sarcasm/run-clang-format
# > Each translation completely replaces the format string · # > for the diagnostic. # > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation · # # It's not pretty, due to Python 2 & 3 compatibility. encoding_py3 = {} if sys.version_info[0] >= 3: encoding_py3['encoding'] = 'utf-8' ·
Author   Sarcasm
🌐
GitHub
github.com › llvm-mirror › clang › blob › master › tools › clang-format › clang-format.py
clang/tools/clang-format/clang-format.py at master · llvm-mirror/clang
April 23, 2020 - fallback_style = vim.eval('g:clang_format_fallback_style') · def get_buffer(encoding): if platform.python_version_tuple()[0] == '3': return vim.current.buffer · return [ line.decode(encoding) for line in vim.current.buffer ] · def main(): # Get the current text.
Author   llvm-mirror
🌐
GitHub
github.com › ssciwr › clang-format-wheel
GitHub - ssciwr/clang-format-wheel: clang-format python wheels
This project packages the clang-format utility as a Python package.
Starred by 103 users
Forked by 21 users
Languages   CMake 51.2% | Python 44.8% | C++ 4.0% | CMake 51.2% | Python 44.8% | C++ 4.0%
🌐
PyPI
pypi.org › project › clang-format-all
clang-format-all · PyPI
Format entire directories of source files with clang-format. This tool also allows to check for formatting without modifying files. ... License: GNU General Public License v3 (GPLv3) (GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc....) ... This is a python script that will run clang-format -i on your code.
      » pip install clang-format-all
    
Published   Oct 03, 2022
Version   0.1.6
Find elsewhere
🌐
PyPI
pypi.org › project › clang-format › 9.0.0
clang-format · PyPI
Precompiled python wheels containing the clang-format and python support files.
      » pip install clang-format
    
Published   Nov 20, 2019
Version   9.0.0
🌐
GitHub
github.com › Sarcasm › run-clang-format
GitHub - Sarcasm/run-clang-format: A wrapper script around clang-format, suitable for linting multiple files and to use for continuous integration · GitHub
Copy run-clang-format.py in your project, then run it recursively on directories, or specific files:
Starred by 261 users
Forked by 70 users
Languages   Python 98.9% | C++ 1.1%
🌐
GROMACS
manual.gromacs.org › current › dev-manual › code-formatting.html
Automatic source code formatting - GROMACS 2026.0 documentation
Python sources can be automatically formatted with Black from Python 3.9.3. C++ source code can be automatically formatted using clang-format since GROMACS 2020. It automatically applies the guidelines in Guidelines for code formatting and in Guidelines for #include directives.
🌐
GitHub
raw.githubusercontent.com › llvm-mirror › clang › master › tools › clang-format › clang-format-diff.py
clang-format-diff.py - GitHub
Example usage for git/svn users: git diff -U0 --no-color HEAD^ | clang-format-diff.py -p1 -i svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i """ from __future__ import absolute_import, division, print_function import argparse import difflib import re import subprocess import sys if sys.version_info.major >= 3: from io import StringIO else: from io import BytesIO as StringIO def main(): parser = argparse.ArgumentParser(description=__doc__, formatter_class= argparse.RawDescriptionHelpFormatter) parser.add_argument('-i', action='store_true', default=False, help='apply edits to files inst
🌐
GitLab
gitlab.cosma.dur.ac.uk › swift › swiftsim › merge requests › !1732
install clang-format using pip, don't expect users to have the correct one (!1732) · Merge requests · SWIFT / SWIFTsim · GitLab
Turns out one can install clang-format through pip, just like the python formatter black. This is surely a better way, as it doesn't require users to provide the correct version themselves, and is portable.
🌐
LLVM
releases.llvm.org › 3.8.0 › tools › clang › docs › ClangFormat.html
ClangFormat — Clang 3.8 documentation
There is an integration for vim which lets you run the clang-format standalone tool on your current buffer, optionally selecting regions to reformat. The integration has the form of a python-file which can be found under clang/tools/clang-format/clang-format.py.
🌐
Opensource.com
opensource.com › article › 17 › 1 › coding-style
Using Clang-format to ensure clean, consistent code | Opensource.com
January 6, 2017 - This removes the need to review pull requests for coding style, and ensures our code base has a uniform style. We have also extended this to our Python code using flake8, a style-guide enforcement tool. Developers can apply the style to their changes easily. I usually run clang-format -i path/to/changed.*, and there are other ways to use the tool.
🌐
Python.org
discuss.python.org › python help
Pep 7 compatible clang format config - Python Help - Discussions on Python.org
September 29, 2024 - Hey, I ran into this thread when looking for the PEP 7 compatible C code formatting configuration. I found that the CPython repo does not have it yet. I made a .clang-format configuration. I hope it is helpful. ▶ .clang-format
🌐
Smhk
smhk.net › note › 2024 › 07 › getting-started-with-clang-format
Getting started with clang-format - smhk
Just as Black and isort can be used to format Python code, clang-format can be used to format C/C++/C# code (and more1).