Search
ctrl+/
Ask AI
ctrl+.
Light
Dark
System
Sign in

Using Gel with Jupyter Notebook​

  1. Install Jupyter Notebook

  2. Install the Gel Python library with pip install gel

  3. Set the appropriate connection environment variables required for your Gel instance

    For Gel Cloud instances

    • GEL_INSTANCE- your instance name (<org-name>/<instance-name>)

    • GEL_SECRET_KEY- a secret key with permissions for the selected instance.

      You may create a secret key with the CLI by running gel cloud secretkey create or in the Gel Cloud UI.

    For other remote instances

    • GEL_DSN- the DSN of your remote instance

      DSNs take the following format: gel://<username>:<password>@<hostname-or-ip>:<port>/<branch>. Omit any segment, and Gel will fall back to a default value listed in our DSN specification

    For local Gel instances

    • GEL_INSTANCE- your instance name

    • GEL_USER & GEL_PASSWORD

    Usernames and passwords

    Gel creates an admin user by default, but the password is randomized. You may set the password for this role by running alter role admin { set password := '<password>'; }; or you may create a new role using create superuser role <name> { set password := '<password>'; };.

  4. Start your notebook by running jupyter notebook. Make sure this process runs in the same environment that contains the variables you set in step 3.

  5. Create a new notebook.

  6. In one of your notebook's blocks, import the Gel library and run a query.

    Copy
    import gel
    
    client = gel.create_client()
    
    def main():
        query = "SELECT 1 + 1;" # Swap in any query you want
        result = client.query(query)
        print(result[0])
    
    main()
    
    client.close()