# Upload

## *class* <mark style="color:purple;">Upload</mark>

Uploads are the interface for bringing data into Redivis. They are associated with a particular table, and can be created on any table belonging to an unreleased version of a dataset. Multiple uploads can be added to a table, in which case they are "stacked" together (equivalent to a union join, with mixed schemas supported).

## Constructors

<table data-header-hidden><thead><tr><th width="342">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="table/table.upload"><strong><code>table.upload</code></strong></a>(upload_name)</td><td>Construct a reference to an upload. <code>upload_name</code> is optional, and will be inferred based on the file name if not provided (for non-file uploads, the default name will be set to the current timestamp).</td></tr></tbody></table>

## Examples

[See more upload examples ->](https://docs.redivis.com/api/client-libraries/redivis-python/examples/uploading-data)

{% tabs %}
{% tab title="Upload tabular file" %}

```python
dataset = redivis.user("user_name").dataset("dataset_name", version="next")
table = dataset.table("table_name")

upload = table.upload().create(
        "./data.csv",           # Path to file, data frame, bytes, etc
        type="delimited",       # Inferred from file extension if not provided
        remove_on_fail=True,    # Remove the upload if a failure occurs
        wait_for_finish=True,   # Wait for the upload to finish processing
        raise_on_fail=True      # Raise an error on failure
    )
```

{% endtab %}

{% tab title="Upload multiple files" %}

```python
dataset = redivis.user("user_name").dataset("dataset_name", version="next")
table = dataset.table("table_name")

for filename in os.listdir("/path/to/data/directory"):
    upload = table.upload().create(
        os.path.join(directory, filename)
    )
```

{% endtab %}
{% endtabs %}

## Attributes

| **`table`**      | A reference to the [Table](https://docs.redivis.com/api/client-libraries/redivis-python/reference/table) instance that constructed this upload.                                                                               |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`properties`** | A dict containing the [API resource representation of the upload](https://docs.redivis.com/api/resource-definitions/upload#get). This will only be populated after certain methods are called, particularly the `get` method. |

## Methods

<table data-header-hidden><thead><tr><th width="430">Name</th><th>Description</th></tr></thead><tbody><tr><td><a href="upload/upload.create"><strong><code>Upload.create</code></strong></a>(data[, ...])</td><td>Create an upload with the provided data and/or configuration.</td></tr><tr><td><a href="upload/upload.delete"><strong><code>Upload.delete</code></strong></a>()</td><td>Delete an upload.</td></tr><tr><td><a href="upload/upload.exists"><strong><code>Upload.exists</code></strong></a>()</td><td>Check whether an upload exists.</td></tr><tr><td><a href="upload/upload.get"><strong><code>Upload.get</code></strong></a>()</td><td>Fetch an upload and populate <code>upload.properties</code></td></tr><tr><td><a href="upload/upload.insert_rows"><strong><code>Upload.insert_rows</code></strong></a>(rows, *[, update_schema])</td><td>Insert rows into an upload of type <code>"stream"</code></td></tr><tr><td><a href="upload/upload.list_variables"><strong><code>Upload.list_variables</code></strong></a>([max_results])</td><td>List the <a href="variable">variables</a> associated with a given upload.</td></tr><tr><td><a href="upload/upload.to_"><strong><code>Upload.to_*</code></strong></a>([max_results, *, ...])</td><td>Various methods to read data out of an imported (but not yet released) upload. Mirrors the various <a href="table">Table.to_*</a> methods (e.g., <code>upload.to_pandas_dataframe()</code></td></tr><tr><td><a href="upload/upload.variable"><strong><code>Upload.variable</code></strong></a>(name)</td><td>Reference a <a href="variable">Variable</a> within this upload.</td></tr></tbody></table>
