Metadata-Version: 2.5
Name: intosql
Version: 0.2.0
Summary: Convert spreadsheets, CSV and JSON into SQL with the IntoSQL API.
Project-URL: Homepage, https://intosql.com/docs/sdks/python
Project-URL: Documentation, https://intosql.com/docs/sdks/python
Project-URL: Repository, https://github.com/alfonsobries/intosql
Project-URL: Changelog, https://github.com/alfonsobries/intosql/blob/main/sdks/python/CHANGELOG.md
Author: IntoSQL
License-Expression: MIT
License-File: LICENSE
Keywords: converter,csv,excel,mysql,postgresql,sql,sqlite,xlsx
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Database
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx<1,>=0.27
Description-Content-Type: text/markdown

# IntoSQL for Python

Convert spreadsheets (XLSX, XLS, ODS), CSV and JSON into SQL for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server or Oracle with the [IntoSQL API](https://intosql.com/developers). Column types are inferred and dirty values fixed, so the script loads on the first try.

```sh
pip install intosql
```

Python 3.9 or newer. The API is part of IntoSQL Pro; make a key in Settings, API keys.

## Convert a file

```python
import os
from intosql import IntoSQL, spec

intosql = IntoSQL(os.environ["INTOSQL_API_KEY"])

conversion = intosql.convert(
    "ventas.xlsx",
    name="ventas.xlsx",
    spec=spec("postgresql", table="ventas"),
)

print(conversion["report"]["rows"]["converted"], conversion["output"]["url"])
```

The file streams to storage as it is; the output URL downloads the script for ten minutes. Read the conversion again (`intosql.conversions.retrieve(id)`) for a fresh one.

A MySQL or MariaDB dump (`.sql`, `.sql.gz`) converts to PostgreSQL like any file. Its report lists each table in `tables`, with its own columns, fixes and problems, where the dump came from in `source`, and the views, triggers, routines and events it did not carry in `not_converted`.

```python
conversion = intosql.convert("shop.sql.gz", name="shop.sql.gz", spec=spec("postgresql"))

for table in conversion["report"].get("tables", []):
    print(table["name"], table["rows"])
```

## Convert a file by URL

```python
conversion = intosql.convert_url(
    "https://example.com/exports/ventas.csv",
    spec=spec("mysql"),
)
```

## Check a webhook

Save a webhook address in Settings, API keys, and IntoSQL calls it when a conversion is done, failed or canceled.

```python
from intosql import parse_webhook

# Raises WebhookSignatureError when the signature doesn't match.
event = parse_webhook(
    request.get_data(),
    request.headers.get("IntoSQL-Signature", ""),
    os.environ["INTOSQL_WEBHOOK_SECRET"],
)
```

## Errors and retries

Failed requests raise `IntoSQLError` with the HTTP `status`, a `code` that doesn't change (`needs_pro`, `over_quota`, `too_big`, `invalid_spec`, `invalid_url` and more) and the `request_id`. A conversion that ends as failed raises `ConversionFailedError` with its `code` and the engine's `problems`. Rate limits, a full account, server errors and lost connections are retried twice with the same idempotency key (`max_retries` changes it); `already_started` never is.

Every endpoint: [intosql.com/developers](https://intosql.com/developers). This SDK: [intosql.com/docs/sdks/python](https://intosql.com/docs/sdks/python).
