跳转到主要内容

从JupyterLab发送电子邮件

项目描述

jupyterlab_email

一个JupyterLab扩展,可以从浏览器发送notebook电子邮件。

Build Status codecov PyPI PyPI npm

选项

  • 将内联notebook作为带有代码的电子邮件发送
  • 将内联notebook作为不带代码的电子邮件发送
  • 将notebook作为带有代码的HTML附件发送
  • 将notebook作为不带代码的HTML附件发送
  • 将notebook作为带有代码的PDF附件发送
  • 将notebook作为不带代码的PDF附件发送
  • 将输出数据附加为CSV、TSV、PDF、PNG或Excel电子表格

安装

pip install jupyterlab_email
jupyter labextension install jupyterlab_email
jupyter serverextension enable --py jupyterlab_email

添加模板

安装服务器扩展,并将以下内容添加到 jupyter_notebook_config.py

c.JupyterLabEmail.smtp_servers = [{'name': 'gmail',
                                   'domain': 'gmail.com',
                                   'username': '<YOUR USERNAME>',
                                   'smtp': 'smtp.gmail.com',
                                   'port': 465}]

从notebook创建电子邮件

使用 jupyterlab_email._email 中的函数

def make_email(path, model, from_, type='email', template='', code=False, subject='',
               also_attach='none', also_attach_pdf_template='', also_attach_html_template=''):
    '''
        path        : path to notebook
        model       : notebook itself (in case deployment strips outputs or
                      notebook not available except through ContentsManager)
        from_       : address to send the email from
        type        : type to convert notebook to
        template    : template to use when converting notebook
        code        : include input cells in notebook
        subject     : subject of email
        also_attach : also attach pdf/html/both
    '''

将dataframe作为csv或电子表格附加

jupyterlab_email.attachments

def attach(data, filename, type):

修改 jupyterlab_email.attachments.EXCEL_ENGINE 以使用不同的excel writer(默认为 xlsxwriter

内联LaTeX

jupyterlab_email.attachments

def latex(expression):
    import matplotlib.pyplot as plt
    fig, ax = plt.subplots(figsize=(10, 1))
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    ax.axis('off')
    plt.text(0, 0.6, r'$%s$' % expression, fontsize=25)
    plt.show()

由以下支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页