Exploring Database Connectivity Using JupyterHub Environment

In this blog post, we will explore how to connect to a database using a JupyterHub environment. By leveraging Python Kernel with sql magic command, we can easily interact with databases such as Postgresql.

To begin, we first need to load the sql extension by using the %load_ext sql command. This allows us to run SQL queries directly within our Jupyter notebook.

Next, we create an environment variable DATABASE_URL using the SQL Alchemy format. This variable contains all the necessary information to connect to the database, including the username, database name, and password.

To validate our database connectivity, we can write a simple query to retrieve data from the information schema table. This helps us ensure that we can successfully communicate with the database.

Here is the information you can use to connect to the database:

  • User Name: YOUR_OS_USER_sms_user
  • Database Name: YOUR_OS_USER_sms_db
  • Password: Your lab password provided by us

By following these steps, you can easily establish a connection to the database and start querying data for your analysis.


Connecting to a database in a JupyterHub environment is a straightforward process, thanks to the sql magic command and SQL Alchemy format. By setting up the environment variable and running SQL queries directly in the notebook, you can seamlessly interact with the database to retrieve the information you need.

If you are looking to sharpen your database querying skills, don’t forget to check out our labs that provide hands-on practice and guidance on working with databases. Happy querying!