The Grok framework is by nature component driven.  It uses the Zope Component Architecture (ZCA).  This means that it uses the idea of Objects which implement Interfaces to make Components that provide integration and function.  This is a very powerful concept for a number of reasons.

By way of disambiguation, we use the term Widget to refer to user interface components such as  select boxes, menus and form inputs. When Angular.js and React folks speak of developing Web Components, they refer to client-side Widgets, forms or other UI elements based upon TypeScript coded objects.

In refererence to Grok, as a tradiitional web framework, the ZCA provides the application building blocks used to build an application server.  These building blocks are described by Interfaces, and become pluggable Components.  By abstracting away implementation detail, one gains versatility, simplicity, plugability, extensibility and maintainabiliy.

It is a commonly held view that application logic, business rules, and general architecture is best managed in the browser, and that there is no place for the monolith application servers commonly found in earlier years.  Yet, it is good to remember that Python web frameworks such as Django, Pyramid, and yes even Flask remain popular, and have their place.  Newer emerging technologies such as HTMX may yet see a revival of the need for substantial server-side business logic, and modular application development.

Server side components may be used to produce widgets represented as snippets of HTML.  Grok does this very well indeed.  These widgets are static though, unless some Javascript control is added to provide the needed reactivity.  Nevertheless, one may often gain time and simplicity rewards by opting for less browser-heavy coding.

Validation of data inputs at the server, access control to data and API's, and user management are all functions which have to be performed in an application server, regardless of the extent to which these functions and data may be cached or duplicated within browser-side logic.  Again, Grok excells at these functions, largely due to the plethora of natively adopted Zope Toolkit functions available to softare developers. 

When these factors are considered, it becomes plain that the "lightweight API server" may not be as easily achievable as one might think, nor is that application model always desirable in every instance.

To those who have built programs using the C# or Java languages, the concept of an interface, or software components implementing interfaces should be quite familiar to you.  Although Python does not enforce Zope interfaces, they do bring significant utility to the language.

If you as a developer are comfortable with a more formal approach to software development, and with the concepts behind component architectures, then Grok is a good match for you.

The ZODB

ZODB (The Z-Object Database) is a simple, non relational Python object database which provides persistence for your Python objects without you having to do much.

Grok seamlessly integrates with the ZODB object database, and for many projects this will be the only database you need.  The design and maintenance overheads of relational databases are eliminated if one uses the ZODB for storage.  However, one is not limited to this approach, and Grok will also integrate well through Storm or SQLAlchemy to any relational database of your choice.  MongoDB also has a wrapper available.

Standard development tools

When writing Grok applications, you use the same standard text editor or IDE (eg. Eclipse / PyCharm / VS Code) you would use to create any other Python application.  This means you get all the benefits such as syntax highlighting, introspection, command line completion, automatic documentation, version control integration with systems such as Git or SVN, and collaborative team development.

"...but isn't Grok through the web (TTW)"?

No, it is not.   Grok is based on the Zope Toolkit (ZTK) and the Zope Component Architecture.  Zope 2, Zope 4 & Zope 5 are based on the same foundation, and support TTW development, if that us what you want to do.  The popular Plone content management system relies quite heavily on TTW aspects of Zope.  There is a library called five.grok, which ports some of the functionality of grok back into Zope.

Easy to read and maintain source code

Coding for Grok is similar in many ways to that of more popular micro frameworks such as Flask, but with a few differences.  Grok uses URL traversal as a means to identifying a model which represents your data, and a view which can render a response to the HTTP request, while other frameworks use explicit request routing to directly identify only the view and view arguments from which to produce a response. 

Therefore, coding a Grok view is simpler in many cases since your view already has access to the data model instance needed to produce a response at the time it is called, and there is often no need to include database lookup code within the view.

Traversal

Traversal is a great way to build web sites.  Each part in the URL can identify a model, a method, attribute or view by name.  Models are stored persistently in the ZODB, and attributes or methods in models may be flagged as traversable.  Views are identified at the end of the traversal chain and would apply to the most recently identified data object.  The ZODB is hierarchical, like a file system or directory, so this whole process is very efficient indeed.

In the words of John Stahl (former Plone foundation president), "Data in Zope is like a flowchart.  Data in other web application frameworks is like a spreadsheet."

Modularity

Because components are so modular, it is easy to extend the function of an existing site without altering unrelated code.  This means that Grok is very suitable to ad hoc changes or multi-developer teams working on the same project. Python modules can be produced as self contained units to provide new functionality, and this approach greatly improves testing and maintenance of code.  Conversely, some other frameworks lead to monolithic files (eg. routes.py, configure.py, etc) or import dependency problems.

Extensibility

Since the Zope Toolkit already provides a rich selection of pluggable components, it is easy to implement some otherwise complex features.  Even though there are some standard modules for most things, it is relatively easy to plug in your own version as a replacement for existing modules. For example, to implement an LDAP based authentication and plug that into the Pluggable Authentication Utility infrastructure.

Simplicity

Grok is a lot simpler to learn, use and maintain than a great number of other web development tools out there.  It is (subjectively speaking)

  • Far simpler than PHP both syntactically as well as regards using frameworks such as Laravel.
  • Django implements it's own ORM which means you need to know all about relational databases to use it well.
  • The simple project with Django is a lot more complex to maintain than an equivalent Grok site, and the complex Django site is a lot more work than the equivalent complex Grok site.
  • Far easier to produce something decent in plain Grok than in Zope-2
  • Way more discoverable and maintainable than a Zope 2 equivalent project

This site will try to prove the above sweeping statements.

Rich legacy of library code

There are some really great libraries available, for example schema based automatic forms generation based upon zope.formlib, or z3c.form, which make implementing a site a real pleasure.  The consistent use of interfaces in the design of a site makes it adaptable for many things unforseen at the start of a project.

Based on Zope, Grok is really fast and scalable, outperforming many other web frameworks.  It integrates well with WSGI, and testing or debugging a Grok application is made simple by configuring your IDE to use the specialised interpreter created as part of the buildout based installation.

The Zope framework is very much alive largely due to the continuous use and development of commonly used libraries and features for the Plone content management system.  Although Plone is based upon the Zope 2 framework, and Grok on Zope 3, many, if not all of the libraries have been back ported to work with Zope 2.  The popular Pyramid framework also uses the same Zope Toolkit that Grok uses. So, although there may not be much direct activity visible for Zope 3 or Grok, under the hood the project is still very much alive and well.

There are many other nice things about developing apps with Grok, which only become clear over time through continued use of the framework.

 

Grok 4 Noobs

What does Grok do particularly well?