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
Metadata
Release files for detect-indent 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| detect-indent-1.0.0.tar.gz | 4.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| detect_indent-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / detect-indent-1.0.0.tar.gz
| Download URL | detect-indent-1.0.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3817859afbbc758b1ab7576cfc0e7de2c24f1cb04c2ca7566051479f57824144
|
|
BLAKE2b-256 checksum How to use checksums |
1b161dd92d922a5f00f6254bfc2f4ec6cf11451b90ae4c3d4eebb27549748295
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / detect_indent-1.0.0-py3-none-any.whl
| Download URL | detect_indent-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ef6baaac5b0efd7795cb09904e2340117f3354768a00ac33165f618d03e268f
|
|
BLAKE2b-256 checksum How to use checksums |
3d928b11fdf9b8a6e53b5dafba4c118144ae91d6d1cd0a4caabfea2fcd1ffcd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|