Using Jupyter Notebook for testing

I wanted a better way to test my code so I thought why not install Jupyter Notebook on server and then test my code there.
I followed the steps from this site ( 5 easy steps to start editing python notebooks over SSH - Willem's Fizzy Logic ) . I can successfully open Jupyter Notebook but when I try to call frappe methods I get error.

import frappe
frappe.get_all(‘Item’)

And the error:


RuntimeError Traceback (most recent call last)
in ()
----> 1 frappe.get_all(‘Item’)

/home/frappe/frappe-bench/apps/frappe/frappe/init.pyc in get_all(doctype, *args, **kwargs)
1153 if not “limit_page_length” in kwargs:
1154 kwargs[“limit_page_length”] = 0
→ 1155 return get_list(doctype, *args, **kwargs)
1156
1157 def get_value(*args, **kwargs):

/home/frappe/frappe-bench/apps/frappe/frappe/init.pyc in get_list(doctype, *args, **kwargs)
1126 “”"
1127 import frappe.model.db_query
→ 1128 return frappe.model.db_query.DatabaseQuery(doctype).execute(None, *args, **kwargs)
1129
1130 def get_all(doctype, *args, **kwargs):

/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.pyc in execute(self, query, fields, filters, or_filters, docstatus, group_by, order_by, limit_start, limit_page_length, as_list, with_childnames, debug, ignore_permissions, user, with_comment_count, join, distinct, start, page_length, limit, ignore_ifnull, save_user_settings, save_user_settings_fields, update, add_total_row, user_settings)
75 self.ignore_ifnull = ignore_ifnull
76 self.flags.ignore_permissions = ignore_permissions
—> 77 self.user = user or frappe.session.user
78 self.update = update
79 self.user_settings_fields = copy.deepcopy(self.fields)

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/werkzeug/local.pyc in getattr(self, name)
345 if name == ‘members’:
346 return dir(self._get_current_object())
→ 347 return getattr(self._get_current_object(), name)
348
349 def setitem(self, key, value):

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/werkzeug/local.pyc in _get_current_object(self)
308 return getattr(self.__local, self.name)
309 except AttributeError:
→ 310 raise RuntimeError(‘no object bound to %s’ % self.name)
311
312 @property

RuntimeError: no object bound to session

2 Likes

Have you run frappe.connect() first?

edit: Julia Evans has a neat talk Diving into Open Data with IPython Notebook & Pandas - PyCon 2014 that https://www.youtube.com/watch?v=rEalbu8UGeo

Hey, guys
I was able to do that using Jupyter as you can see in the image below, I installed the Jupyter inside the virtual environment and I created the Jupyter notebook inside the sites folder and it worked

Jupyter is a really powerful tool for testing

6 Likes

What is baz3 ?

The site name

2 Likes

Thanks ever so much you two for the pointers and incentive to jump into Jupyter -

It’s been on my list so finally yesterday I got it working in a bridged network VM.

Already I am convinced it’s truly a well conceived fun tool to support code exploration, trial and error testing and development, and to document learnings.

Many scientific and academic communities use Jupyter Notebooks to share their work for eg
A gallery of interesting Jupyter Notebooks

That strategy may be productive here too?

cheers and thanks

edit: this helped Jupyter Notebook Tutorial: Introduction, Setup, and Walkthrough

Some food for thought teaser screenshots


2 Likes

You are welcome sir :blush:
Yeah Jupyter notebooks are perfect for sharing, testing and documenting code snippets