Skip to main content

SimpleFacturaSDK

SDK oficial en Python para integrar tus sistemas con SimpleFactura (ChileSystems): facturación, clientes, productos, proveedores, folios, boletas de honorarios, cesión, partner y Payku.

Características

  • Cliente asincrónico basado en aiohttp.
  • Servicios separados por dominio (Facturacion, Productos, Clientes, etc.).
  • Modelos tipados para requests/responses.
  • Manejo de autenticación y renovación de token.

Requisitos

  • Python >=3.6
  • pip

Instalación

Desde PyPI:

pip install SimpleFacturaSDK

Para desarrollo local:

git clone https://github.com/pereacarlos/SimpleFacturaSDK-python.git
cd SimpleFacturaSDK-python
pip install -r requirements.txt

Configuración

Crea un archivo .env en la raíz de tu proyecto:

SF_USERNAME=tu_usuario
SF_PASSWORD=tu_contraseña
SF_BASE_URL=https://api.simplefactura.cl

Opcional: archivo config.py (si quieres forzar URL base por código):

import os
from dotenv import load_dotenv

load_dotenv()
BASE_URL = os.getenv("SF_BASE_URL", "https://api.simplefactura.cl")

Uso rápido

import asyncio
import os
from dotenv import load_dotenv
from SimpleFacturaSDK.client_simple_factura import ClientSimpleFactura

load_dotenv()

username = os.getenv("SF_USERNAME")
password = os.getenv("SF_PASSWORD")

async def main():
    async with ClientSimpleFactura(username, password) as client:
        # Servicios disponibles
        facturacion = client.Facturacion
        productos = client.Productos
        proveedores = client.Proveedores
        clientes = client.Clientes
        sucursales = client.Sucursales
        folios = client.Folios
        configuracion = client.ConfiguracionService
        bhe = client.BoletaHonorarioService
        usuarios = client.Usuarios
        cesion = client.CesionService
        partner = client.PartnerService
        payku = client.PaykuService

        print("Cliente inicializado correctamente")

if __name__ == "__main__":
    asyncio.run(main())

Ejemplo: obtener PDF de DTE

import asyncio
from SimpleFacturaSDK.client_simple_factura import ClientSimpleFactura
from SimpleFacturaSDK.models.GetFactura.Credenciales import Credenciales
from SimpleFacturaSDK.models.GetFactura.DteReferenciadoExterno import DteReferenciadoExterno
from SimpleFacturaSDK.models.GetFactura.SolicitudPdfDte import SolicitudPdfDte


async def main():
    async with ClientSimpleFactura("usuario", "password") as client:
        solicitud = SolicitudPdfDte(
            credenciales=Credenciales(
                rut_emisor="76269769-6",
                nombre_sucursal="Casa Matriz",
            ),
            dte_referenciado_externo=DteReferenciadoExterno(
                folio=4117,
                codigoTipoDte=33,
                ambiente=0,
            ),
        )

        resp = await client.Facturacion.obtener_pdf(solicitud)
        if resp.status == 200:
            with open("factura.pdf", "wb") as f:
                f.write(resp.data)
            print("PDF guardado")
        else:
            print(f"Error {resp.status}: {resp.message}")


if __name__ == "__main__":
    asyncio.run(main())

Ejecutar tests

python -m unittest discover -s SimpleFacturaSDK/tests -p "test_*.py" -v

Cobertura

Si ejecutas tests con cobertura y aparece:

ModuleNotFoundError: No module named 'coverage'

instala la dependencia en el mismo intérprete que usa VS Code:

python -m pip install coverage

Luego puedes correr, por ejemplo:

python -m coverage run -m unittest discover -s SimpleFacturaSDK/tests -p "test_*.py"
python -m coverage report -m

Problemas comunes

  • Credenciales incorrectas: revisa SF_USERNAME y SF_PASSWORD.
  • SF_BASE_URL no definida: asegúrate de tener .env o config.py correctamente configurado.
  • VS Code usa otro Python: selecciona el intérprete correcto en Python: Select Interpreter.

Documentación oficial

Metadata

Release files for SimpleFacturaSDK 1.2.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 SimpleFacturaSDK 1.2.1
File Size Uploaded Provenance Actions
simplefacturasdk-1.2.1.tar.gz 79.1 kB Without provenance Details for simplefacturasdk-1.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for SimpleFacturaSDK 1.2.1
File Interpreter ABI Platform Actions
simplefacturasdk-1.2.1-py3-none-any.whl Python 3 none any Details for simplefacturasdk-1.2.1-py3-none-any.whl

Total release size: 252.1 kB

Release files / simplefacturasdk-1.2.1.tar.gz

Download URL simplefacturasdk-1.2.1.tar.gz
Size 79.1 kB
Tags Source
SHA-256 checksum
How to use checksums
88debd5a1a9a4e4a0faed4b0a477434ee73357af19b710e258eb5b1ca0aa6dfe
BLAKE2b-256 checksum
How to use checksums
460062f361b7e29f4ec08f439119555cf6967c26d85fa9e41486830884e91da6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / simplefacturasdk-1.2.1-py3-none-any.whl

Download URL simplefacturasdk-1.2.1-py3-none-any.whl
Size 173.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18c116ce5fb4718384bfd14e81259b0192af59545a60264dfd470204da4d8370
BLAKE2b-256 checksum
How to use checksums
3c2d235e60bc6e4af2cb2fd4254683a46ad3fe4e241901b0789ae3b298af1404
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for SimpleFacturaSDK 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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