pip install Pygments
python
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
code = '''
def hello_world():
print("Hello, World!")
'''
lexer = PythonLexer()
formatter = HtmlFormatter()
highlighted_code = highlight(code, lexer, formatter)
print(highlighted_code)