Gramex 1.64 makes deployment easier, with better support multiple apps per server, multiple logins per app, and secure and offline deployment.
You can access the IDE Beta at https://gramex.gramener.com/. The current version allows you to clone projects from Github and Gitlab, as well as create a repo from scratch.
Running two Gramex instances on one server, e.g. at
server.com/app1/
at port 8001 and server.com/app2/
at port 8002, is more robust.
When redirecting, Gramex needs the actual URL it’s deployed at (not localhost:8001
). For example,
when logging in or screen capturing.
Just add an X-Request-URI
HTTP header in your proxy server to the actual URL. Gramex handles
redirections automatically after that.
The configuration for nginx looks like this:
proxy_set_header X-Request-URI $request_uri;
Two apps on one server may still need different login methods.
E.g. app1/
uses Google Auth.
app2/
uses Database Auth.
You can now define a different cookie for each app. Configure app1/
as follows:
app:
session:
cookie: app1-sid # Use 'app1-sid' cookie for this app instead of 'sid'
A user may need to log in with multiple accounts. E.g. to share charts on multiple social media via Google, Facebook, Twitter, and Database Auth.
The documentation on multiple logins explains how to set this up, along with a demo
Passwords, access tokens, and other sensitive information needs to be protected. Gramex now
supports a .secrets.yaml
file where you can save these securely.
If you can edit files on the server (directly, or via CI), add an uncommitted .secrets.yaml
file with your secrets, like this:
PASSWORD: your-secret-password
GOOGLE_AUTH_SECRET: your-secret-key
TWITTER_SECRET: your-secret-key
# ... etc
These variables are available in gramex.yaml
as $PASSWORD
, $GOOGLE_AUTH_SECRET
,
$TWITTER_SECRET
, etc. For example:
url:
login/google:
pattern: /$YAMLURL/login/
handler: GoogleAuth
kwargs:
key: add-your-key-directly # This is not a secret
secret: $GOOGLE_AUTH_SECRET # This comes from .secrets.yaml
If you can’t edit files on the server, you can pick up encrypted secrets from a public URL in 3 steps.
.secrets.yaml
:SECRET_URL: https://pastebin.com/raw/h75e4mWx
SECRET_KEY: SECRETKEY # Replace with your secret key
When Gramex loads, it loads SECRET_URL
(ignoring comments beginning with #
) and decrypts it using your SECRET_KEY
.
Read more about deploying secrets
Offline installation is now a simple 2-step process:
gramex-offline
gramex-offline
folder into the target system (which need not have an Internet connection)Gramex FormHandler connections to 14 databases are now documented.
CaptureHandler reloads a page to take a screenshot. This can be slow. To avoid this, you can use html2canvas and FileSaver.js, which are now part of the UI component library.
Trigger the download as follows:
html2canvas(document.querySelector(".chart")) // Pick the element to download
.then((canvas) => {
canvas.toBlob((blob) => {
saveAs(blob, "chart.png"); // Pick your filename
});
});
To protect an entire app, i.e. add auth on all pages, use:
app:
auth: true # All pages require login -- including CSS/images on login page!
Use with caution. This will be used as the default auth on every handler.
The CSS/JS/images on your login page won’t appear unless you set auth: false
on those URLs.
There’s a new tutorial on Creating an ML classifier application.
This is designed as a step-by-step 1.5 hour workshop for new Gramex users to introduce Gramex, show interactions, and teach them how to build a simple machine learning classifier.
bootstraptheme.css
is now cached in the browser
for a day – improving page load speed.moment.js
is deprecated in
favor of dayjs
. Both will remain as part of Gramex, for backward
compatibility.X-Requested-With: XMLHttpRequest
to ignore the check. You don’t need to fetch an XSRF token
from the server..woff
) instead of
displaying them on screen.We promised two features in this release that are delayed. These will get pushed to November.
In addition, the October 2020 release (1.65) will feature:
… and more.
See the Gramex installation and upgrade instructions
Note: Gramex 1.64 does not work with Python 3.8. We recommend Python 3.7.
The Gramex code base has: