Jupyter notebook — Prestart dependencies

Matjaž Hozjan
3 min readApr 15, 2022

--

Jupyter It is an open source web app and great solution for use with live coding, documenting, graphs, plots etc.

Photo by Monica Sauro on Unsplash

This short tutorial is meant to help improve your everyday use when launching it. Let’s say you are using Amazon Web Services or some other libraries that you know that in most of your notebooks will be used. And you don’t want to have multiple bash files or use some other solution to pre-run all scripts that you use often.

Solution for MAC user’s goes as follows. Browse to your root folder and enable look for hidden folders (Press “Command” + “Shift” + “ . ” ) Now the .ipython folder will appear. Inside it is folder profile_default and browse to startup. File needs to be named as “start.py”. Note: After you save the file in the folder kernel restart is a must to take effect.

start.py

file can have your favourite imports, settings and even your favorite or most used functions. All those options that are not in function will be pre-run at each jupyter startup, and function will be available for you at any time.

My solution is based on avoiding manually starting some bash files with code, so instead I am just launching jupyter and all is there when I need it. So no extra lines or anything is needed. Meaning that in case that you have a lot of functions maybe it can cause some mess and is better to go with bash option to use each for specific use. in the end is up to you and your project. For me at my work this is a great way to go as for connection to AWS is launched quickly and with no hassle. Plus some other perks as pandas import etc with display max options etc…

Example of use.
# Example of start.py file:import sqlalchemy
import pandas as pd

USER = "user_mail@somemail.com"

# GROUP: For AWS
GROUP = "aws-group"

EXAMPLE_QUERY = "SELECT * FROM table LIMIT 10;"

#Pandas dependencies
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)


def get_connection(user, password):
"""Some magic :) """
root
Startup folder

Clap, follow for more!

Cheers!

--

--

Matjaž Hozjan
Matjaž Hozjan

Written by Matjaž Hozjan

FX, stock trader and full time DataScientist at SportRadar AG

No responses yet