# Python

### Requisitos previos

Para poder seguir esta guía, primero necesitarás:

* [Obtener un access\_token de Afip SDK](https://app.afipsdk.com)

### 1. Instalación

Agregá la librería de Afip SDK en Python

{% tabs %}
{% tab title="Pip" %}

```bash
pip install afip.py
```

{% endtab %}
{% endtabs %}

### 2. Crear una instancia de la clase Afip

Para usar los Web Services de ARCA se necesita un certificado digital, pero con Afip SDK podés empezar en modo desarrollo usando el CUIT 20-40937847-2 sin necesidad de uno.

Si preferís [usar tu propio certificado](#usar-tu-propio-certificado-opcional), al final te mostramos cómo.

{% tabs %}
{% tab title="index.py" %}

```python
from afip import Afip

afip = Afip({ 
    "CUIT": 20409378472,
    "access_token": "TU_ACCESS_TOKEN" # Obtenido de https://app.afipsdk.com
})
```

{% endtab %}
{% endtabs %}

### 3. Llamar al método del Web Service que necesites

Con la instancia creada ya podés realizar las llamadas a los Web Services que necesites.

{% content-ref url="/pages/mVTz5YrKc8PCEeJKHt0W" %}
[Web services](/siguientes-pasos/web-services.md)
{% endcontent-ref %}

Si el Web Service que necesitás no se encuentra en la lista de la documentación, podés llamarlo siguiendo esta guía:

{% content-ref url="/pages/4zlCsTNGo99FZGfrhpZn" %}
[Otro web service](/siguientes-pasos/web-services/otro-web-service.md)
{% endcontent-ref %}

Podés usar la referencia de la API para obtener ejemplos de cómo usar los métodos de todos los web services de ARCA.

{% embed url="<https://afipsdk.com/docs/api-reference/introduction/>" %}

También podés usar las guías del blog de Afip SDK para Python:

{% embed url="<https://afipsdk.com/blog/category/Python/>" %}

Y un proyecto de ejemplo listo para usar:

{% embed url="<https://github.com/AfipSDK/afip-sdk-billing-example-python>" %}

***

### Usar tu propio certificado <sup><sub>(Opcional)<sub></sup>

Primero, obtenemos el certificado siguiendo esta guía.

{% embed url="<https://afipsdk.com/blog/como-obtener-certificado-para-web-services-arca/>" fullWidth="false" %}

Y luego lo agregamos a la instancia de la clase Afip.

{% tabs %}
{% tab title="index.py" %}

```python
from afip import Afip

# Certificado (Puede estar guardado en archivos, DB, etc)
cert = open("ruta/a/certificado.crt").read()

# Key (Puede estar guardado en archivos, DB, etc)
key = open("ruta/a/key.key").read()

# CUIT del certificado
tax_id = 20111111112

afip = Afip({
    "CUIT": tax_id,
    "cert": cert,
    "key": key,
    "access_token": "TU_ACCESS_TOKEN" # Obtenido de https://app.afipsdk.com
))
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.afipsdk.com/integracion/python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
