Multipurpose python utils
Project description
JANIA LIB
Librería multipropósito en Python: utilidades para procesamiento de configuración, extracción de datos de PDF usando LLM y limpieza avanzada de JSON.
Instalación
Requiere Python 3.7 o superior.
pip install jania
O bien, clona el repositorio:
git clone https://github.com/julianin/JANIALIB.git
cd JANIALIB
pip install .
Dependencias
- toml
- PyYAML
- python-dotenv
- pdf2image
- Pillow
- openai (opcional, solo si usas funciones LLM)
Funcionalidades principales
1. Limpieza y formateo de JSON: cleanJSON
Función para extraer, limpiar y formatear el primer bloque JSON válido de un texto (útil para outputs de LLM o APIs poco estrictas).
Uso básico:
from jania import cleanJSON
json_str = cleanJSON(raw_text)
Parámetros:
text: (str) Texto de entrada donde buscar JSON.indent: (int, opcional) Espacios de indentación para el JSON de salida. Default: 2.debug: (bool, opcional) Si es True, también devuelve el fragmento corregido que se intentó parsear. Default: False.
Devuelve:
- Un string con el JSON limpio y formateado, o None si no se encuentra JSON válido.
Ejemplo:
json_str = cleanJSON('output: {a:1, b:2, c:true}')
print(json_str)
# {
# "a": 1,
# "b": 2,
# "c": true
# }
2. Gestión de configuración: env y env_config
Utilidades para leer configuración multi-formato y variables de entorno, con prioridad flexible.
env_config(filename)
Carga un archivo de configuración extra (acepta .py, .toml, .yaml/.yml, .json, .txt). El archivo se usará como fuente prioritaria tras el entorno.
Uso:
from jania import env, env_config
env_config('settings.toml')
Parámetro:
filename: Ruta al archivo de configuración.
env(key, fallback=None)
Busca el valor de una clave de configuración (str) siguiendo este orden:
- Variable de entorno
- Config cargado por
env_config() - config.py
- settings.toml
- settings.yaml
fallback(valor por defecto)
Uso:
valor = env('API_KEY', fallback='1234')
Devuelve:
- Valor de la clave (str) o
fallbacksi no se encuentra.
3. Extracción y análisis de PDF con LLM: extractPDF
Convierte cada página de un PDF a imagen y consulta un modelo LLM Vision (por defecto: gpt-4-vision-preview) para analizarlo.
Uso típico:
from jania import extractPDF
with open('documento.pdf', 'rb') as f:
respuesta = extractPDF(
prompt='Resume el documento:',
archivo=f,
nombre_archivo='documento.pdf',
model='gpt-4-vision-preview', # opcional
max_images=10, # opcional
openai_api_key=None # opcional
)
Parámetros:
prompt: (str) Instrucción para el LLM.archivo: (BinaryIO) Archivo PDF abierto en modo binario.nombre_archivo: (str) Nombre del archivo (para almacenamiento temporal).model: (str, opcional) Modelo de OpenAI Vision a usar. Default: "gpt-4-vision-preview".max_images: (int, opcional) Número máximo de páginas/imágenes a procesar. Default: 10.openai_api_key: (str, opcional) API Key de OpenAI. Si no se da, se busca en configuración/env.
Devuelve:
- Diccionario con la respuesta del LLM bajo la clave
respuesta_llm.
Notas:
- Requiere la librería
openaiy una API Key válida. - Si no tienes la clave, colócala en una variable de entorno
OPENAI_API_KEYo config compatible.
Ejemplo de uso general
from jania import env, env_config
from jania import cleanJSON
from jania import extractPDF
# Configuración
env_config('settings.toml')
clave = env('OPENAI_API_KEY')
# Limpieza de JSON
json_str = cleanJSON('Responde en json: {"x":1, "y":true, "z":null}')
# Análisis de PDF
with open('ejemplo.pdf', 'rb') as f:
resultado = extractPDF('Describe cada página', f, 'ejemplo.pdf', openai_api_key=clave)
print(resultado['respuesta_llm'])
Licencia
MIT
Autor
Julian Ania
NOTES
git tag -a v0.3.1 -m "Release v0.3.1"
git push origin v0.3.1
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jania-0.3.4.tar.gz.
File metadata
- Download URL: jania-0.3.4.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
048e486c69c734dfafc3e8f89169abbae04a1d3979d2ac3afddb241675aa39c7
|
|
| MD5 |
14496318b6f8ee45c1ea728481f938eb
|
|
| BLAKE2b-256 |
5d334678266fc57b1dbe7fcd1a7aa6cfca818921f3c1af671d0fad1c681da000
|
Provenance
The following attestation bundles were made for jania-0.3.4.tar.gz:
Publisher:
publish.yml on julianin/JANIALIB
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jania-0.3.4.tar.gz -
Subject digest:
048e486c69c734dfafc3e8f89169abbae04a1d3979d2ac3afddb241675aa39c7 - Sigstore transparency entry: 257702227
- Sigstore integration time:
-
Permalink:
julianin/JANIALIB@8334937c550bea82168796699c2e446b1085adb7 -
Branch / Tag:
refs/tags/v0.3.5 - Owner: https://github.com/julianin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8334937c550bea82168796699c2e446b1085adb7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file jania-0.3.4-py3-none-any.whl.
File metadata
- Download URL: jania-0.3.4-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78249f6666ed3071decd0ad22786a3a7afd4be0d359a5d1d74c2712a7a300b4f
|
|
| MD5 |
d54c3ec65df8d34a7680778a0fba8f17
|
|
| BLAKE2b-256 |
e2c1d827947c4dd53b6d9b8fd6b92d698852937b22f968408d12c8aa53f2c2d1
|
Provenance
The following attestation bundles were made for jania-0.3.4-py3-none-any.whl:
Publisher:
publish.yml on julianin/JANIALIB
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jania-0.3.4-py3-none-any.whl -
Subject digest:
78249f6666ed3071decd0ad22786a3a7afd4be0d359a5d1d74c2712a7a300b4f - Sigstore transparency entry: 257702247
- Sigstore integration time:
-
Permalink:
julianin/JANIALIB@8334937c550bea82168796699c2e446b1085adb7 -
Branch / Tag:
refs/tags/v0.3.5 - Owner: https://github.com/julianin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8334937c550bea82168796699c2e446b1085adb7 -
Trigger Event:
push
-
Statement type: