# Get Upload Sessions Details

Files are uploaded in an upload session. You can list all upload sessions or get a single session to check its status, creation time, and files uploaded.

***

## About This Task

### Sessions

<AsyncUploadInfo />

## Prerequisites

<SdkInstallationSteps />

[Upload Files with Python](./upload-files-with-python.mdx). This creates a session. 

## List All Sessions Script Examples

Here's an example code you can use to list all active sessions:

<Tabs>
  <TabItem value="sync" label="Sync">
  
  ```python
  
    from deepset_cloud_sdk.workflows.sync_client.files import list_upload_sessions

    for session_batch in list_upload_sessions(
      api_key="<deepset API key>",
      workspace_name="<your_workspace>",
      is_expired=False,  # Set to True if you want to list expired sessions
      batch_size=100,  # Adjust the batch size as needed
    ):
      for session in session_batch:  # List of length 100
        print(session.session_id)
  ```

  </TabItem>
  <TabItem value="async" label="Async">
  
  ```python
  
    from deepset_cloud_sdk.workflows.async_client.files import list_upload_sessions

    async def my_async_context() -> None:
        async for session_batch in list_upload_sessions(
            api_key="<deepset Cloud API key>",
            workspace_name="<your_workspace>",
            is_expired=False,  # Set to True if you want to list expired sessions
            batch_size=100,  # Adjust the batch size as needed
        ):
            for session in session_batch:  # List of length 100
                print(session.session_id)
  ```

  </TabItem>
</Tabs>

## Get Details of a Single Session Script Examples

Here's the code you can use to view a single upload session. (You can get session IDs from the `list_upload_sessions()` method.)

<Tabs>
  <TabItem value="sync" label="Sync">
  
  ```python
    from deepset_cloud_sdk.workflows.async_client.files import get_upload_session
    from uuid import UUID

    session_id = UUID(
        "enter-your-session-id-here"
    )  # Replace with your actual upload session ID returned by `list_upload_sessions`

    session_details = get_upload_session(
      api_key="<deepset API key>",
      workspace_name="<your_workspace>",
      session_id=session_id,
    )
    print(session_details)

  ```

  </TabItem>
  <TabItem value="async" label="Async">
  
  ```python
    from deepset_cloud_sdk.workflows.async_client.files import get_upload_session
    from uuid import UUID

    session_id = UUID(
        "enter-your-session-id-here"
    )  # Replace with your actual upload session ID returned by `list_upload_sessions`

    async def my_async_context() -> None:
        session_details = await get_upload_session(
            api_key="<deepset Cloud API key>",
            workspace_name="<your_workspace>",
            session_id=session_id,
        )
        print(session_details)
  ```

  </TabItem>
</Tabs>

## Close a Session

You may need to close a session manually, for example, because you reached the limit of 10 open sessions to trigger file ingestion. You can do so using the [Close Session](/docs/api/main/close-session-api-v-1-workspaces-workspace-name-upload-sessions-session-id-put.api.mdx) REST API endpoint. You'll need the upload session ID, <ProductShortName /> API key, and the name of the workspace where you're uploading the files.

Copy this code, replacing the variables:

```curl
curl --request PUT \
     --url https://api.cloud.deepset.ai/api/v1/workspaces/<WORKSPACE_NAME>/upload_sessions/<SESSION_ID> \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <deepset API key' \
     --header 'content-type: application/json' \
     --data '{"status":"CLOSED"}'
```
