Detects the indentation type and size of any string.
Project description
detect-indent for Python 
Python port of sindresorhus/detect-indent All attribution goes to that project.
Detect the indentation of code
Pass in a string of any kind of text and get the indentation.
Use cases
- Persisting the indentation when modifying a file.
- Have new content match the existing indentation.
- Setting the right indentation in your editor.
Install
pip install detect-indent
Usage
from detect_indent import detect_indent
sample_string = '''
Example string
with an indentation
of two spaces
'''
indent = detect_indent(sample_string)
print(indent) # {'amount': 2, 'type': 'space', 'indent': ' '}
API
Returns a dictionary with the following stats about indentation:
amount{number} - Amount of indentation, for example 2. Will be 0 if indentation could not be detected.type{'tab' | 'space' | None} - Type of indentation. Possible values are'tab','space'orNoneif no indentation is detectedindent{string} - A string representing the actual indentation, for example a string of two spaces.
Algorithm
The current algorithm looks for the most common difference between two consecutive non-empty lines. More Details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file detect-indent-1.0.0.tar.gz.
File metadata
- Download URL: detect-indent-1.0.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3817859afbbc758b1ab7576cfc0e7de2c24f1cb04c2ca7566051479f57824144
|
|
| MD5 |
63f91df914603aeff24d952f1e48e7d8
|
|
| BLAKE2b-256 |
1b161dd92d922a5f00f6254bfc2f4ec6cf11451b90ae4c3d4eebb27549748295
|
File details
Details for the file detect_indent-1.0.0-py3-none-any.whl.
File metadata
- Download URL: detect_indent-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ef6baaac5b0efd7795cb09904e2340117f3354768a00ac33165f618d03e268f
|
|
| MD5 |
db2566fb44fefd3e9c2b89981eb13b84
|
|
| BLAKE2b-256 |
3d928b11fdf9b8a6e53b5dafba4c118144ae91d6d1cd0a4caabfea2fcd1ffcd7
|