# Download logged table in run locally

**URL:** <https://community.wandb.ai/t/download-logged-table-in-run-locally/3507>\
**Category:** W&B Help\
**Tags:** tables\
**Created:** [December 7, 2022, 3:42am UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507 "2022-12-07T03:42:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamedr002](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@mohamedr002](https://community.wandb.ai/u/mohamedr002)\
**Post date:** [December 7, 2022, 3:42am UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/1 "2022-12-07T03:42:36Z")

</div>

Hi all,

I have been trying to download and open Wandb table locally. I have managed to get the corresponding table and its id, however, I cannot find way to download the table and open it as CSV for example.

````auto
runs[0].summary['avg_results'].keys()
dict_keys(['_type', 'ncols', 'nrows', 'sha256', 'artifact_path', '_latest_artifact_path', 'path', 'size'])```

Above is a snippet of what I have managed to reach, how can I go from this point to get the table file and read it as cdv
````

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [December 7, 2022, 11:03am UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/2 "2022-12-07T11:03:29Z")

</div>

Hi @mohamedr002 thank you for writing in! You could use the API to download the Table in json format which you could then easily convert to pandas dataframe. Please see below a code snippet, and feel free to ask more questions:

```auto
import wandb
api = wandb.Api()
run = api.run(f"ENTITY/PROJECT/{run_id}")
table = run.logged_artifacts()[0]
table_dir = table.download()
table_name = "my_table_name"
table_path = f"{table_dir}/{table_name}.table.json"
with open(table_path) as file:
    json_dict = json.load(file)
df = pd.DataFrame(json_dict["data"], columns=json_dict["columns"])

```

Please note that logged\_artifacts() is an iterator, and for simplicity I added [0] to return only the first entry as an example. Would this work for you?

---

<div class="post-metadata">

**Author:** ![mohamedr002](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@mohamedr002](https://community.wandb.ai/u/mohamedr002)\
**Post date:** [December 7, 2022, 11:20am UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/3 "2022-12-07T11:20:59Z")

</div>

Hi Thanos,

Thank you so much for your clear response. But only one issue that when I logged the table I didn’t log it as artifacts I have just used the workspace

> wandb.log(wandb.table)

Will your provider solution still work? Or it requires logging the table as artifact?

---

<div class="post-metadata">

**Author:** ![mohamedr002](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@mohamedr002](https://community.wandb.ai/u/mohamedr002)\
**Post date:** [December 7, 2022, 12:32pm UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/4 "2022-12-07T12:32:33Z")

</div>

> [@thanos-wandb](#):
>
> ```auto
> df = pd.DataFrame(json_dict["data"], columns=json_dict["columns"])
> 
> ```

Hi Thanos,

I have tried your script it worked but not directly. The issue as I mentioned that I don’t have the artifact name, so I managed to get the table path directly.

```auto
avg_table_path = best_run.summary['avg_results']['path']
avg_table = json.load(open(avg_table_path))
avg_df = pd.DataFrame(avg_table['data'], columns= avg_table['columns'])

```

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [December 7, 2022, 12:33pm UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/5 "2022-12-07T12:33:21Z")

</div>

Hi @mohamedr002 that’s automatically done when you’re logging wandb.Table objects. You could click on the Artifacts icon (left panel) from your project’s workspace. Another way to get directly `table` would be:

`table = run.use_artifact("run-<run-id>-<table_name>:<tag>").get("<table_name>")`

Please let me know if that works for you, or if you have any further questions.

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [December 7, 2022, 12:40pm UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/6 "2022-12-07T12:40:37Z")

</div>

Hi @mohamedr002 we both posted same time, is this issue now resolved for you by getting the `avg_table_path` first? May I also ask if these logged tables were wandb.Table objects? in that case it would also create an artifact.

---

<div class="post-metadata">

**Author:** ![mohamedr002](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@mohamedr002](https://community.wandb.ai/u/mohamedr002)\
**Post date:** [December 7, 2022, 12:47pm UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/7 "2022-12-07T12:47:12Z")

</div>

Yes, you are right, I found the table as already been logged as artifiact, but rather than getting the name and directory separately, I used the ‘path’ element that exist in the table artifact dictionary. I am really thankful for your prompt response. Really appreciated!

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [December 7, 2022, 1:01pm UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/8 "2022-12-07T13:01:52Z")

</div>

Hi @mohamedr002 glad to hear that, thanks a lot for posting your workaround for future reference! I am closing this ticket for now, but please feel free to reach out to us if you have any other questions!

---

<div class="post-metadata">

**Author:** ![satpalsr](https://avatars.discourse-cdn.com/v4/letter/s/74df32/32.png) [@satpalsr](https://community.wandb.ai/u/satpalsr)\
**Post date:** [December 24, 2022, 8:17am UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/9 "2022-12-24T08:17:07Z")

</div>

Hey, I am trying to use, `table = run.use_artifact("run-<run-id>-<table_name>:<tag>").get("<table_name>")`  
Can you help how run should be initialised?

What should I pass as arguments here?  
`run = wandb.Api().artifact()`

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [December 28, 2022, 8:10pm UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/10 "2022-12-28T20:10:47Z")

</div>

Hi @satpalsr there are two ways to access this artifact, either by initialising a run such as `run = wandb.init()` and then you could use` run.use_artifact` method or by using our public API. In the latter case, you could do the following:

```auto
api = wandb.Api()
artifact = api.artifact('entity/project/artifact-name:alias')

```

I hope this helps!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [February 26, 2023, 8:10pm UTC](https://community.wandb.ai/t/download-logged-table-in-run-locally/3507/11 "2023-02-26T20:10:52Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
