<jupyter_start><jupyter_text>Tutorial 1a: Reflections in this tutorial, we will extend the `Basics` notebook and look at the reflection module in SQLAlchemy to see how we can load tables from a pre-existing database.  Requirements You will need to have sqlalchemy installed:        pip install sqlalchemy<jupyter_code>import sqlalchemy as sq<jupyter_output><empty_output><jupyter_text>Loading Database There is a sample notebook in `Data` folder named `sample.db` which we will load.<jupyter_code>engine = sq.create_engine('sqlite:///Data/sample.db', echo=False)<jupyter_output><empty_output><jupyter_text>Define a metadata object to get a listing of all tables and reflect the full set.<jupyter_code>meta=sq.MetaData()
meta.reflect(bind=engine)
object_table = meta.tables['object']
distance_table = meta.tables['distance']<jupyter_output><empty_output><jupyter_text>Fetching Data Before performing any queries, we need to bind our metadata to engine.<jupyter_code>meta.bind=engine
object_table.select().execute().fetchall()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09013282732447818, 'fraction_numerical': 0.0009487666034155598, 'mean_word_length': 7.307086614173229, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '206510', 'license': 'MIT', 'n_tokens_mistral': 324, 'n_tokens_neox': 316, 'n_words': 96, 'path': 'Notebooks/01-a.LoadingDatabases.ipynb', 'repo_name': 'drphilmarshall/AstroAlch_tutorial', 'size': '1054'}