🐍 Criando um servidor para o Jupyter Notebook

Crie uma nova configuração:

jupyter notebook --generate-config

No arquivo criado coloque essas duas linhas:

c.NotebookApp.allow_origin = '*' #allow all origi
c.NotebookApp.ip = '0.0.0.0' # listen on all 

E depois no terminal digite comando:

jupyter notebook --ip xx.xx.xx.xx --port 8888

Troque o xx.xx.xx.xx pelo ip da maquina.

Dica de Segurança:

Voce poderá colocar uma senha no seu Notebook digitando o comando abaixo:

c = get_config()
c.NotebookApp.password = u'sha1:6c2164fc2b22:ed55ecf07fc0f985ab46561483c0e888e8964ae6'

Voce poderá gerar sua própria senha sha1 com o seguinte código python:

from IPython.lib import passwd
password = passwd("secret")
password

Referencias:

[1] – https://testnb.readthedocs.io/en/stable/examples/Notebook/Configuring%20the%20Notebook%20and%20Server.html

[2] – https://testnb.readthedocs.io/en/stable/examples/Notebook/Configuring%20the%20Notebook%20and%20Server.html

Instalando e usando o Ply no Python

Ply é um analisador sintático muito pratico para quem quer fazer esse tipo de coisa no python, onde ele retorna sua saída em forma de tokens, a sua instalação se da de maneira fácil através do pip.

Instalação

$ pip install ply

Exemplo

# ------------------------------------------------------------
# calclex.py
#
# tokenizer for a simple expression evaluator for
# numbers and +,-,*,/
# ------------------------------------------------------------
import ply.lex as lex

# List of token names.   This is always required
tokens = (
'NUMBER',
'PLUS',
'MINUS',
'TIMES',
'DIVIDE',
'LPAREN',
'RPAREN',
)

# Regular expression rules for simple tokens
t_PLUS    = r'\+'
t_MINUS   = r'-'
t_TIMES   = r'\*'
t_DIVIDE  = r'/'
t_LPAREN  = r'\('
t_RPAREN  = r'\)'

# A regular expression rule with some action code
def t_NUMBER(t):
    r'\d+'
    t.value = int(t.value)    
    return t

# Define a rule so we can track line numbers
def t_newline(t):
    r'\n+'
    t.lexer.lineno += len(t.value)

# STRING contendo caracteres a serem ignorados(espaços e tabs)
t_ignore  = ' \t'

# Se deu Erro
def t_error(t):
    print("Illegal character '%s'" % t.value[0])
    t.lexer.skip(1)

# Construindo o LEX
lexer = lex.lex()

# Entrada de Exemplo
data = '''
3 + 4 * 10
+ -20 *2
'''

# Passa a entrada para o analizador
lexer.input(data)

# Tokenize
while True:
    tok = lexer.token()
    if not tok: 
        break      # Termina a entrada
    print(tok)



Referências:

[ 1 ] – https://www.dabeaz.com/ply/ply.html