Skip to content

Instantly share code, notes, and snippets.

@andrewdoss-bit
Last active September 9, 2021 20:40
Show Gist options
  • Save andrewdoss-bit/920574c06becd5b693edec3d563badf6 to your computer and use it in GitHub Desktop.
Save andrewdoss-bit/920574c06becd5b693edec3d563badf6 to your computer and use it in GitHub Desktop.
Landing page Python snippets
#####
# Connect to bit.io
import bitdotio
b = bitdotio.bitdotio(<YOUR_BITIO_KEY>)
# You can call SDK methods directly from the b object
b.list_repos()
# The b object also provides access to a psycopg2 cursor for arbitrary SQL
conn = bit_conn.get_connection()
cur = conn.cursor()
#####
# Create a repo
import bitdotio
# Connect to bit.io
b = bitdotio.bitdotio(<YOUR_BITIO_KEY>)
# Construct a repo object
r = bitdotio.model.repo.Repo(name='my_new_repo',
description='My new repository.',
is_private=True)
# Create the repo
b.create_repo(repo=r)
# Confirm repo creation
b.list_repos()
# Import data
import bitdotio
# Connect to bit.io
b = bitdotio.bitdotio(<YOUR_BITIO_KEY>)
# From file
# Download demo csv here:
# https://docs.bit.io/docs/uploading-data#:~:text=video-game-sales.csv
with open('video-game-sales.csv', 'r', encoding='utf-8') as f:
b.create_import_file(f, 'my_new_repo', table_name='video_game_sales_csv')
# From URL
import_url = bitdotio.model.import_url.ImportUrl('https://storage.googleapis.com/bitdotio-demo-datasets/video-game-sales.csv',
'video_game_sales_url',
'my_new_repo')
b.create_import_url(import_url=import_url)
#####
# Query data
import bitdotio
# Connect to bit.io
b = bitdotio.bitdotio(<YOUR_BITIO_KEY>)
# Get psycopg2 cursor
with b.get_connection() as conn:
cur = conn.cursor()
cur.execute('SELECT date, name, local_price FROM "bitdotio/big_mac_index"."big_mac_index"')
print(cur.fetchone())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment