Gramex 1.78 release notes

Gramex 1.78 supports TypeScript, Time series models, CORS with auth, and more.

TypeScript

FileHandler can compile TypeScript. The default FileHandler compiles any .ts file into JS. For example, this typescript.ts file:

type WindowStates = "open" | "closed" | "minimized";
function getLength(obj: WindowStates | WindowStates[]) {
  return obj.length;
}

is rendered as:

function getLength(obj) {
  return obj.length;
}
//# sourceMappingURL=typescript.ts?map

See typescript.ts

To enable this in your FileHandler, add:

kwargs:
    ...
    ts: '*.ts'      # Compile .ts files into JS

Time Series Models

MLHandler supports time series forecasting.

This now lets MLHandler perform 3 distinct tasks:

  1. Classification: Categorize a data point into discrete buckets (e.g. good/bad)
  2. Regression: Predict a number based on other values (e.g. temperature based on pressure)
  3. Time series: Predict a number based on time and, optionally, other values (e.g. stock price)

To specify a time series model, use class: SARIMAX. This uses the SARIMAX algorithm in statsmodels.

mlhandler/forecast:
  pattern: /$YAMLURL/forecast
  handler: MLHandler
  kwargs:
    data:
      url: $YAMLPATH/inflation.csv # Inflation dataset
    model:
      index_col: index # Use index column as timestamps
      target_col: R
      class: SARIMAX
      params:
        order:
          [7, 1, 0] # Creates ARIMA estimator with (p,d,q)=(7,1,0)
          # Add other parameters similarly

CORS with auth

When one server sends a request to another server via browser JavaScript, we need to enable Cross-Origin Resource Sharing (CORS).

This release makes CORS easy. Just add cors: true to the URL’s kwargs to enable CORS. For example, this page returns session information to pages from any server:

url:
  deploy-cors:
    pattern: /$YAMLURL/cors
    handler: FunctionHandler
    kwargs:
      function: handler.session
      cors: true # Enable CORS

You can restrict CORS to specific domains or HTTP methods. Read more about CORS.

Authorization HTTP methods

To authorize the user for some HTTP methods (e.g. POST, PUT, DELETE) but not others (e.g. GET), use this:

url:
  public-read:
    pattern: /$YAMLURL/public-read
    handler: FunctionHandler
    kwargs:
      function: f'Method = $${handler.request.method}, User = $${handler.current_user}'
      auth:
        methods: [POST, PUT, DELETE]

Any GET, OPTIONS or other HTTP requests to /public-read can be made by anyone. But POST, PUT, DELETE can only be made by logged-in users.

Auth HTTP methods

Dynamic SASS imports

FileHandler supports ○a ?@import=path/to/filename.sass to import SASS files dynamically into other SASS files. The import file path must be relative to the requested SASS file or the directory Gramex is running in.

Bug fixes

Backward compatibility & security

Gramex 1.78 is backward compatible with previous releases unless the release notes say otherwise. Automated builds test this.

Every Gramex release is tested for security vulnerabilities using the following tools.

  1. Bandit tests for back-end Python vulnerabilities. See Bandit results
  2. npm-audit tests for front-end JavaScript vulnerabilities. See npm-audit results
  3. Snyk for front-end and back-end vulnerabilities. See Synk results
  4. ClamAV for anti-virus scans. See ClamAV results

Statistics

The Gramex code base has:

How to install

See the Gramex installation and upgrade instructions.