Skip to content

Instantly share code, notes, and snippets.

@vinaykudari
Last active December 21, 2022 03:45
Show Gist options
  • Save vinaykudari/b4650404e3d8ea1918961f00716e438b to your computer and use it in GitHub Desktop.
Save vinaykudari/b4650404e3d8ea1918961f00716e438b to your computer and use it in GitHub Desktop.
Viewing Table Details
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"import sqlalchemy as db"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"engine = db.create_engine('sqlite:///census.sqlite')\n",
"connection = engine.connect()\n",
"metadata = db.MetaData()\n",
"census = db.Table('census', metadata, autoload=True, autoload_with=engine)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['state', 'sex', 'age', 'pop2000', 'pop2008']\n"
]
}
],
"source": [
"# Print the column names\n",
"print(census.columns.keys())"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Table('census', MetaData(bind=None), Column('state', VARCHAR(length=30), table=<census>), Column('sex', VARCHAR(length=1), table=<census>), Column('age', INTEGER(), table=<census>), Column('pop2000', INTEGER(), table=<census>), Column('pop2008', INTEGER(), table=<census>), schema=None)\n"
]
}
],
"source": [
"# Print full table metadata\n",
"print(repr(metadata.tables['census']))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment