Skip to content

nripankadas07/dotpath

dotpath

Dotted-key get/set/has/del over nested dicts and lists. Zero deps.

from dotpath import get, set_, has, delete, paths

d = {"users": [{"name": "alice"}, {"name": "bob"}]}
get(d, "users.1.name")            # 'bob'
get(d, "users.5.name", default=None)  # None

set_(d, "users.0.email", "a@x")
# {"users": [{"name": "alice", "email": "a@x"}, {"name": "bob"}]}

has(d, "users.0.email")           # True
delete(d, "users.0.email")
list(paths(d))                     # ['users.0.name', 'users.1.name']

\\. escapes a literal dot inside a key segment. List indices are integers; negatives count from the end.

MIT.

About

Dotted-key get/set/has/del over nested dicts and lists, like jq's path syntax minus the language. Zero dependencies.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages