Skip to content

harupy/pyformatter

Repository files navigation

Pyformatter

REST API to format python code.

https://pyformatter.com

Getting Started

# if pipenv is not installed yet
pip install pipenv

# force pipenv to create .venv in the current directory
export PIPENV_VENV_IN_PROJECT=1

# install dependencies
pipenv install

# run the app
python run.py

Run with Docker

docker-compose up

Example in Python

see examples.

import requests

code = """
a=1+2*3/4

def foo():
    pass
"""

params = {
  'code': code,
  'indent_size': 2
}

url = 'https://pyformatter.com/api/format'
resp = requests.get(url, params)
print(resp.json()['code'])

The output looks like:

a = 1 + 2 * 3 / 4


def foo():
  pass

Test

flake8 -v
python -m pytest

Todos

  • Add an option which allows users to choose a code formatter. The current version only supports autopep8.

References

About

REST API to format python code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published