Skip to main content

Parentheses. V1.0.0

Light parentheses parser in Python.

Types (Aliases)

ParenthesesSymbol = str
ParseFlag = int

Constants

PARENTHESES_ALL: ParseFlag = 1
PARENTHESES_OPEN: ParseFlag = 2
PARENTHESES_CLOSE: ParseFlag = 3

PARENTHESES_ROUND_OPEN: ParenthesesSymbol = '('
PARENTHESES_ROUND_CLOSE: ParenthesesSymbol = ')'

PARENTHESES_SQUARE_OPEN: ParenthesesSymbol = '['
PARENTHESES_SQUARE_CLOSE: ParenthesesSymbol = ']'

PARENTHESES_CURLY_OPEN: ParenthesesSymbol = '{'
PARENTHESES_CURLY_CLOSE: ParenthesesSymbol = '}'

PARENTHESES_DOUBLE_QUOTE: ParenthesesSymbol = '"'

PARENTHESES_SINGLE_QUOTE: ParenthesesSymbol = '\''

PARENTHESES_OPEN_SYMBOLS: list[ParenthesesSymbol] = [
    PARENTHESES_ROUND_OPEN,
    PARENTHESES_SQUARE_OPEN,
    PARENTHESES_CURLY_OPEN
]

PARENTHESES_CLOSE_SYMBOLS: list[ParenthesesSymbol] = [
    PARENTHESES_ROUND_CLOSE,
    PARENTHESES_SQUARE_CLOSE,
    PARENTHESES_CURLY_CLOSE
]

PARENTHESES_SYMBOLS = PARENTHESES_OPEN_SYMBOLS + PARENTHESES_CLOSE_SYMBOLS

PARENTHESES_REGEX = r'\(.*?\)|\[.*?\]|\{.*?\}'

PPString class

PPString is a class that represents a parsed parentheses string.

valid_proc() -> bool

Get is parentheses in string valid. (Slower but gives more accurate result).

Examples:

  • parse('(x)').valid_proc() => True

  • parse('(x').valid_proc() => False

valid() -> bool

Get is parentheses in string valid. (Faster but gives less accurate result).

Examples:

  • parse('(x)').valid() => True

  • parse('(x').valid() => False

valid_quotes(_escaping: bool=False) -> bool

Get is quoted parentheses valid.

Examples:

  • parse('"x"').valid_quotes() => True

  • parse('"x\""').valid_quotes(True) => True

  • parse('"x').valid_quotes() => False

  • parse('"x\""').valid_quotes() => False

count(flag: ParseFlag=PARENTHESES_ALL) -> int

Count braces in string.

Examples:

  • parse('(x)').count() => 2

  • parse('(x)').count(PARENTHESES_OPEN) => 1

  • parse('(x)').count(PARENTHESES_CLOSE) => 1

autoclose() -> str

Autoclose brackets.

Examples:

  • parse('{[(x').autoclose() => {[(x)]}

find(remove_braces: bool=False) -> list

Get content in braces.

Examples:

  • parse('(x) [y] {z}').find() => ['(x)', '[y]', '{z}']

  • parse('(x) [y] {z}').find(True) => ['x', 'y', 'z']

remove_braces() -> str

Remove braces in string.

Examples:

  • parse('(x) [y] {z}').remove_braces() => 'x y z'

remove(keep_braces: bool=False) -> str

Remove everything in parentheses.

Examples:

  • parse('(x) [y] {z}').remove() => ' '

  • parse('(x) [y] {z}').remove(True) => '() [] {}'

as_str() -> str

Get string.

Examples:

  • parse('x').as_str() => 'x'

Global functions

parse(string: str) -> PPString

Parse string.

Examples:

  • parse('(x)') => PPString('x')

new_parentheses_symbols(open_symbol: ParenthesesSymbol, close_symbol: ParenthesesSymbol) -> None

Add new parentheses symbols.

Examples:

  • new_parentheses_symbols('<', '>') => None

remove_parentheses_symbols(open_symbol: ParenthesesSymbol, close_symbol: ParenthesesSymbol) -> None

Remove parentheses symbols.

Examples:

  • remove_parentheses_symbols('<', '>') => None

Release files for parentheses 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parentheses 1.0.1
File Size Uploaded
parentheses-1.0.1.tar.gz 4.2 kB Details

Release files / parentheses-1.0.1.tar.gz

Download URL parentheses-1.0.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2c418939db0c285a6a547c630fc2775add119d6f8bc284e15e480c7efaeca8ba
BLAKE2b-256 checksum
How to use checksums
6871adc587578298d87b9d00d9fbdfe381cc6635c9ee68818c59cdca6edd4a48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.9

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page