Skip to content

Realtime Updates

This tutorial is about using Macrometa GDN as a realtime database with local latencies across the globe.


Let's assume your

  • Tenant name is and
  • User password is guest.

Driver download

pyC8 requires Python 3.5+. Python 3.6 or higher is recommended

To install pyC8, simply run

    $ pip3 install pyC8

or, if you prefer to use conda:

    conda install -c conda-forge pyC8

or pipenv:

    pipenv install --pre pyC8

Once the installation process is finished, you can begin developing applications in Python.
With Yarn or NPM

    yarn add jsc8
    npm install jsc8

If you want to use the driver outside of the current directory, you can also install it globally using the `--global` flag:

    npm install --global jsc8

From source,

    git clone
    cd jsC8
    npm install
    npm run dist

Code Sample

from c8 import C8Client
import threading
import pprint
import time

# Variables - URLs
global_url = ""

# Variables - DB
email = ""
password = "guest"
geo_fabric = "_system"
collection_name = "ddos"

# Variables - Data
data = [
    {"ip": "", "action": "block", "rule": "blacklistA"},
    {"ip": "", "action": "block", "rule": "blacklistA"},
    {"ip": "", "action": "block", "rule": "blacklistB"},
    {"ip": "", "action": "block", "rule": "blacklistA"},
    {"ip": "", "action": "block", "rule": "blacklistB"},

pp = pprint.PrettyPrinter(indent=4)

if __name__ == '__main__':

  # Step1: Open connection to GDN. You will be routed to closest region.
  print("\n1. CONNECT: federation: {},  user: {}".format(global_url, email))
  client = C8Client(protocol='https', host=global_url, port=443,
                     email=email, password=password,

  # Step2: Create a collection if not exists
  print("\n2. CREATE_COLLECTION: region: {},  collection: {}".format(global_url, collection_name))
  if client.has_collection(collection_name):
      collection = client.collection(collection_name)
      collection = client.create_collection(collection_name)

  # Subscriber to receive events when changes are made to collection.
  def create_callback():
    def callback_fn(event):
    client.on_change(collection_name, callback=callback_fn)

  # Step3: Subscribe to receive documents in realtime (PUSH model)
  print("\n3. SUBSCRIBE_COLLECTION: region: {},  collection: {}".format(global_url, collection_name))
  rt_thread = threading.Thread(target=create_callback)
  print("Callback registered for collection: {}".format(collection_name))

  # Step4: Subscribe to receive documents in realtime (PUSH model)
  print("\n4. INSERT_DOCUMENTS: region: {},  collection: {}".format(global_url, collection_name))
  client.insert_document(collection_name, document=data)

  # Step5: Wait to close the callback.
  print("\n5. Waiting to close callback")

  # Step6: Delete data.
  print("\n6. DELETE_DATA: region: {}, collection: {}".format(global_url, collection_name))
'use strict'

const jsc8 = require('jsc8');

// Variables - DB
const global_url = "";

// Crete a authenticated instance with Token / Apikey
// const client = new jsc8({url: global_url, token: "XXXX", fabricName= '_system'});
// const client = new jsc8({url: global_url, apiKey: "XXXX", fabricName= '_system'});
// await console.log("Authentication done!!...");

// Or use Email & Password to Authenticate client instance
const client = new jsc8(global_url);

await client.login("", "guest");

const collection_name = "ddos";
let collectionDetails;

// Variables - Data
const data = [
  {"ip": "", "action": "block", "rule": "blacklistA"},
  {"ip": "", "action": "block", "rule": "blacklistA"},
  {"ip": "", "action": "block", "rule": "blacklistB"},
  {"ip": "", "action": "block", "rule": "blacklistA"},
  {"ip": "", "action": "block", "rule": "blacklistB"},

async function createCollection() {
  console.log("\n 2. CREATE_COLLECTION");

      console.log(`Creating the collection ${collection_name}...`);
      const exists_coll = await client.hasCollection(collection_name);
      if (exists_coll === false) {
          await client.createCollection(collection_name);

      // adding a onChange listner for collection
        const listener = await client.onCollectionChange(collection_name);
        listener.on('message',(msg) => console.log("message=>", msg));
        listener.on('open',() => {
        listener.on('close',() => console.log("connection closed"));
    catch (e) {
      await console.log("Collection creation did not succeed due to " + e);

async function insertData() {
  console.log(`\n 3. INSERT_DATA in region ${global_url}`);
  await client.insertDocumentMany(collection_name, data);

async function deleteData(){
  console.log("\n 4. DELETE_DATA");
  await client.deleteCollection(collection_name);

(async function(){
  await createCollection();
  await insertData();
  await deleteData();