Skip to main content

A unified path parser in C for Python

Project description

Universal JS like path parser for python

Specification

1. Overview

This specification defines how to reference properties or indices in a nested data structure using a combined notation:

  1. Dot notation segments: a.b.c
  2. Bracket notation segments: ["a"]["b"][0]
  3. Mixed notation: a["b"].c[0]

It also imposes constraints to avoid ambiguous or invalid dot notation:

  • No leading dots (e.g., .something is invalid).
  • No trailing dots (e.g., something. is invalid).
  • No repeated consecutive dots (e.g., a..b is invalid).

2. Dot Notation Rules

  1. Valid Identifiers Only:
    • Each dot-delimited token (segment) must be a valid identifier in the target environment.
    • This typically means alphanumeric characters plus underscores (e.g., myKey, user2, some_value).
  2. No Leading Dot:
    • A path cannot begin with a dot. For example, .a.b is invalid.
  3. No Trailing Dot:
    • A path cannot end with a dot. For example, a.b. is invalid.
  4. No Consecutive Dots:
    • A path cannot contain .. (two or more consecutive dots). For example, a..b is invalid.

Examples of valid pure dot paths:

  • user.name.first
  • accountDetails.balance
  • config.version

Examples of invalid pure dot paths (under this specification):

  • .leadingDot (leading dot)
  • trailingDot. (trailing dot)
  • double..dots (multiple consecutive dots)

3. Bracket Notation Rules

Bracket notation allows any valid string or number inside square brackets:

["some.key"] ["another space"] [42]

3.1 String Keys

  • Must be enclosed in quotes inside the brackets: ["any string"] or ['any string'].
  • Permits spaces, dots, dashes, or reserved characters in the key.

3.2 Numeric Indices

  • To represent arrays or list indices, use bracket notation with a numeric literal: [0], [10], etc.
  • No quotes needed for a pure integer.

3.3 Constraints on Brackets

  • Bracket notation does not have the same dot-based restrictions (no worry about leading/trailing dots).
  • However, mixing bracket notation into a dot path must still obey the dot-notation constraints for the dot-delimited segments.

4. Mixed Usage

When dot notation and bracket notation are combined, the path can jump between the two. Here are the rules:

  1. Dot notation segments must follow the dot rules (valid identifiers, no leading/trailing dots, no consecutive dots).
  2. Bracket segments can appear anywhere in the path, typically after a valid dot segment or another bracket segment.
  3. A path cannot be just a dot—there must be a valid segment or bracket after/before each dot.

Examples:

  • a.b[0].c
    • a and b are valid identifiers in dot notation, [0] is a bracket for an array index, then .c is back to dot notation.
  • user["personal.info"].preferences["color.theme"]
    • Dot segments: user, preferences
    • Bracket segments: ["personal.info"], ["color.theme"]

5. Unified Path Grammar (Informal)

Here is a conceptual grammar that respects the stricter dot-notation constraints:

Path := DotSegment ( ('.' DotSegment) | BracketSegment )*

DotSegment := ValidIdentifier

BracketSegment := '[' ( StringLiteral | NumberLiteral ) ']'

ValidIdentifier := (Alpha | '') (AlphaNum | '' )* # No dots, no leading digit, no spaces, etc., based on your environment's definition.

StringLiteral := '"' '"' | "'" "'"

NumberLiteral := Digit+

  • Path starts with a DotSegment (this disallows a leading dot).
  • A . must always be followed by another DotSegment (disallowing empty segments or multiple consecutive dots).
  • You can insert a BracketSegment at any point to handle special keys or numeric indices.

No leading/trailing dot is enforced by starting with DotSegment and only permitting subsequent '.' DotSegment pairs. No consecutive dots is enforced by requiring a segment name after each '.'.


6. Example Paths Under This Specification

  1. Pure Dot Notation, All Valid

    • employee.profile.name
    • config.version.major
  2. Mixed Dot & Bracket

    • a.b[0].c
    • root["user data"].info["age.range"][2]
  3. All Bracket

    • ["root"]["user data"]["something.with.dots"][42]
    • Even though you can reference everything in brackets, if you switch to dot notation, any segment must be a valid identifier.
  4. Invalid

    • .leadingDot.segment (leading dot)
    • segment. (trailing dot)
    • a..b (multiple consecutive dots)
    • root[""][""] is technically valid bracket usage for empty strings, but if you wanted empty string segments in dot notation, that’s disallowed here.

7. Traversal Semantics

Implementations using this path specification will:

  1. Parse the path into a sequence of segments (each being either a valid dot identifier or a bracketed key/index).
  2. Traverse the nested data structure in order:
    • For a DotSegment ( DotSegment ): move to the sub-key DotSegment.
    • For a BracketSegment ( [StringLiteral] ): move to the sub-key of that string.
    • For a BracketSegment ( [NumberLiteral] ): move to the array index NumberLiteral.
  3. Stop once all segments have been resolved, returning the final value or indicating a missing path if any key/index does not exist.

8. Conclusion

This specification provides:

  • Strict dot-notation compatibility (no leading/trailing/multiple consecutive dots).
  • Flexible bracket notation to handle any string key (including spaces, symbols, or dots) or numeric index.
  • Mixed usage that seamlessly allows dot segments for valid identifiers and bracket segments for anything else.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

dotdict_parser-0.8.1-cp314-cp314t-musllinux_1_2_x86_64.whl (23.5 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

dotdict_parser-0.8.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (23.9 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

dotdict_parser-0.8.1-cp314-cp314-musllinux_1_2_x86_64.whl (21.5 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

dotdict_parser-0.8.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (21.6 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

dotdict_parser-0.8.1-cp313-cp313-musllinux_1_2_x86_64.whl (21.4 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

dotdict_parser-0.8.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (21.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

dotdict_parser-0.8.1-cp312-cp312-musllinux_1_2_x86_64.whl (21.4 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

dotdict_parser-0.8.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (21.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

dotdict_parser-0.8.1-cp311-cp311-musllinux_1_2_x86_64.whl (20.8 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

dotdict_parser-0.8.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (20.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

dotdict_parser-0.8.1-cp310-cp310-musllinux_1_2_x86_64.whl (20.5 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

dotdict_parser-0.8.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (20.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file dotdict_parser-0.8.1-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0bdf4c443129f55d63d6ccf9d82aa90c201141f731a90b408b7a0cb2bd66206d
MD5 7c23d401e98757cb538d6d5428a02a16
BLAKE2b-256 d60920086e0af3c978fb1e80b748bef6207f0024bd028825088cb2f728fcf763

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 29139da2ef104fcbe68daf424521adfc82a23419fbf9ee2d455a0ed2374346e8
MD5 bfe221d972bc18c09acaf80609553ec9
BLAKE2b-256 b83b56d291e61ddfcbc0fcff09443b894424f07825e7968eb4fd2eabd411baa9

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 36c00519db5ff3f77831029dfa08be1cd6de7c7cc1283d7a4e08c0c60309f837
MD5 254be2c725bb77e98fdd5f7e82c0772b
BLAKE2b-256 56943317f1cc60c44c5367d11e3ba569cc54b9e5a1ec87e3d87580f797e15b11

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 82cdb6e9395c36f28f3051dfbae8a918b7e35ded1f894a9508f1bca5ff3ae83d
MD5 cdf8648328452198d34f767d0001be23
BLAKE2b-256 d133a99712eeeafa148ce485a513d986051b7a0193f169e085a34616b2c7a9dc

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d44d0cc27a9e67a1966dfbf204ba4cdccf3adf75ec2bc3cf932317a2c4109afd
MD5 166a17915b8ad8b4e93ac569401281a6
BLAKE2b-256 d71fab8ae94024a509dd76d72617b560103475f140d4c0fad088f8221baba610

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 556cbe7cbcc648b020991ecb05b55770511efd561dc0346a15e521b8a2cca905
MD5 3b0cbf0b602a5c23ba5b4165fd053a15
BLAKE2b-256 bb72b46922ee41924b35e6c73997ef4bc177ca1914f1d94f0b1c2befede9a589

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f9ad2fef6d0548094bfe6548006d9c41032a2780d03783d96110c464233695a6
MD5 4afd0eb9ee5f343473723746e30d7182
BLAKE2b-256 61124f26ba0032c2429a6bdcf43e9bb625e8c937db39820401ab391bfde3cb95

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 d19f028d763980e646814338a75a46982a1c83aafb12d28bfd3e198d8ed5f102
MD5 f928dd8345d651cc7d763bc834490643
BLAKE2b-256 45195a06905b69f9bbc7d0fcdfabb2b0292cc67e667ed539033ee3f2c4d19d73

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d250a8e4cbe5cdadae7d1b2cda6c1426e4b1c42199f04befc0ee416735b2e490
MD5 fe9c86a210af785602ec9e94227b9ae5
BLAKE2b-256 c52222121a182f9db63a5b823b8011187ac459359c3eb8b29cc748701451f04c

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 16650dc21f0348f004ced02565f83f9c8954a962a31f9a8dc4bca4458f63b836
MD5 3b28e5483588cb95a65e8f69163f1afd
BLAKE2b-256 1850fb2394370661c5b2b5cf07ff272a9c6e1f10d3589fb1176996b1a59987ef

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dca96608db6e8a089e5cd0318e1937e7fa5ec6ccafc29395572e40cf2b17b9e6
MD5 fc679375680c6bff7138dfbd828835aa
BLAKE2b-256 0cf1dbcf0dd2b8ed745b0a9a3c208b5cf3c3b530a311cc88979e1b07ccedacae

See more details on using hashes here.

File details

Details for the file dotdict_parser-0.8.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for dotdict_parser-0.8.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 942c58756f59b7d9ba634d3b6e9419d23f71e566bfb08fa2c84d02a5a6c1bd21
MD5 20c185c24308509bd6096efb5d258d74
BLAKE2b-256 2fba20c398b6a1f135eee7461fca45ab081442bf7806d47f5cdc3d931c2d3d3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page