Skip to content

Instantly share code, notes, and snippets.

@andrewdoss-bit
Created August 10, 2021 23:04
Show Gist options
  • Save andrewdoss-bit/5b9814218245613f185f3e6df99f7786 to your computer and use it in GitHub Desktop.
Save andrewdoss-bit/5b9814218245613f185f3e6df99f7786 to your computer and use it in GitHub Desktop.
Upload csv to bit.io from Python w/ requests
import requests
import pandas as pd
# This is to provide a reproducible csv,
# you can ignore and use your own csv
df_test = pd.DataFrame(
data=[[0, 1, 2], [3, 4, 5]],
columns=['a', 'b', 'c'])
df_test.to_csv('test.csv', index=False)
with open('test.csv', 'rb') as f:
data = f.read()
url = 'https://import.bit.io/<YOUR_USERNAME>/<YOUR_REPO>/test'
headers = {
"Content-Disposition": "attachment;filename='test.csv'",
"Authorization": "Bearer <YOUR_API_KEY>"
}
response = requests.request("POST", url, headers=headers, data=data)
print(response.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment