Skip to content

About

Elegant Data Structure Navigation for Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

derafu-selector

Lectura y escritura en diccionarios mediante selectores. La librería no depende de Django.

Requiere Python 3.14.

Instalación

pip install "derafu-selector @ git+https://github.com/derafu/selector-python.git"

Uso

from derafu_selector import selector

datos = {'emisor': {'rut': 76192083, 'nombre': 'ACME'}, 'tipo': 33}

selector(datos, 'emisor.rut')                 # 76192083
selector(datos, 'emisor.giro||"sin giro"')    # 'sin giro'
selector(datos, 'emisor.giro', 'Servicios')   # True: escribe el valor

Sin value se lee: entrega el valor o None si no se pudo leer. Con value se escribe: entrega True o False. Con debug=True se lanzan las excepciones en vez de entregar None o False.

Selectores

Forma Ejemplo
Llave simple y anidada a, a.b.c
Elemento de una lista lista[1]
Elemento de una lista de diccionarios según otra llave lista[llave=valor:llave_resultado]
Textos entre comillas y concatenación "Total: "(a.b)
Alternativas (el primer valor no vacío) a||b||"por defecto"
IF ternario ((a) = "x" ? (b) : (c))
JSONPath $.a.b
JMESPath jmespath:a.b

Operadores del IF: =, ==, !=, <>, >, >=, <, <=, contains, length e is ("None" o "not None").

También incluye dictionary_read_case_insensitive(), que lee una llave sin distinguir mayúsculas y minúsculas.

Desarrollo

make install-dev PYTHON=python3.14   # crea venv/ con la librería y herramientas
make check                           # ruff, formato, mypy, pyright y pytest

typings/jsonpath.pyi describe los tipos de jsonpath, que no los trae.

Licencia

MIT. Ver LICENSE.

About

Elegant Data Structure Navigation for Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages