Skip to main content

A simple package for generating mdx scripts

Project description

This is a simple library to help building .mdx scripts. It is composed by:

  • A simple syntax module to generate mdx

  • Functions to generate mdx sets from lists, .json arrays or prefined .mdx sets

  • A writer class and a writer context manager

Installation

pip install mdx

Usage

# Usage
from mdx import syntax as s
from mdx import MDXSetConstructor, writerContext
from mdx import loadJson, loadMDX

toyCodeBuilder = MDXSetConstructor(memberPath="[Products].[ProductName]", comment="Product Codes")
colorCodeBuilder = MDXSetConstructor(memberPath="[Colors]", comment="Color Codes")

toys = {
  'dolls' : toyCodeBuilder(codeList=[1,2,3], listName="toy dolls")
}

colors = {
  'blue' : colorCodeBuilder(codeList=['blue', 'cyan'], listName="blues")
}

# Loads .mdx files in path
# Each file becomes available as a tuple member with the file name as key
toys = loadMDX(
  "path/to/toys",
  extraMembers = toys, # Add extra members defined by hand
  toyCodeBuilder
)

# Loads .json files in path
# Each file becomes available as a member of a named tuple with the file name as field
colors = loadJSON(
  "path/to/colors",
  extraMembers = colors,  # Add extra members defined by hand
  colorCodeBuilder
)

# The first two arguments are passed automatically by the context manager
@measure
def volume(writer, sets, name, *expressions, **kwargs):

  # Perform some common .mdx operations here...

  writer.write(
    s.createMeasure(s.measureMember(name),
      s.sumExisting('[Measures].[PurchaseCount]', s.intersect(*expressions)
      )
    )
  )

writer = MDXWriter(name='writer', path='./interestingToys') # by default the path is set on config["OUTPUT_FOLDER"]

# Putting it all together
with writerContext((toys, colors), writer) as (measures, config):

  measures(volume)(
    # the writer and set variables are passed to the measure after the arguments
    'volume of interesting toy purchases',
    s.tuple(toys.dolls, colors.blue),
    s.exclude(
      s.tuple(toys.cars, colors.any),
      s.tuple(toys.cars, colors.red),
    )
  )

# The output will be available at ./interestingToys.mdx

# Configuration options
from mdx import config
config["OUTPUT_FOLDER"] = "./path/to/folder"
config["LIST_BASE_PATH"] = "./path/to/folder"
config["TAB_SIZE"] = 2

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdx-0.1.tar.gz (18.6 kB view details)

Uploaded Source

File details

Details for the file mdx-0.1.tar.gz.

File metadata

  • Download URL: mdx-0.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mdx-0.1.tar.gz
Algorithm Hash digest
SHA256 20ed9abc90a3bb3037e63566fb9282f10d5299a9c00db90cbd03b2cff20bca6e
MD5 cc5fe0761b0199a153475a816bee7ff2
BLAKE2b-256 dabf29209fe9b59d6a007ef36f263a3227296aaf98086284ca59614f3521a945

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page