Skip to main content

TRAC Model Runtime for Python

Project description

TRAC Model Runtime for Python

TRAC is a next-generation data and analytics platform for use in highly regulated environments

The TRAC model runtime provides all the APIs needed to write models for the TRAC platform. It includes an implementation of the runtime library that can be used as a development sandbox, so you can run and debug TRAC models right away from your favourite IDE or notebook. A number of tools are included to make it easy to plug in development data and other settings. When your models are ready they can be loaded into a real instance of TRAC for testing and eventual deployment.

Documentation for the TRAC platform is available at trac-platform.readthedocs.io.

Requirements

The TRAC runtime for Python has these requirements:

  • Python: 3.7 or later
  • Pandas: 1.0 or later
  • PySpark 2.4.x or 3.x

Not every combination of versions will work, e.g. PySpark 3 requires Python 3.8.

Installing the runtime

The TRAC runtime package can be installed directly from PyPI:

pip install trac-runtime

The TRAC runtime depends on Pandas and PySpark, so these libraries will be pulled in as dependencies. If you want to target particular versions, install them explicitly first.

Writing a model

Once the runtime is installed you can write your first TRAC model! Start by inheriting the TracModel base class, your IDE should be able to generate stubs for you:

import trac.rt.api as trac

class SampleModel(trac.TracModel):

    def define_parameters(self) -> tp.Dict[str, trac.ModelParameter]:
        pass

    def define_inputs(self) -> tp.Dict[str, trac.ModelInputSchema]:
        pass

    def define_outputs(self) -> tp.Dict[str, trac.ModelOutputSchema]:
        pass

    def run_model(self, ctx: trac.TracContext):
        pass

You can fill in the three define_* methods to declare any parameters, inputs and outputs your model is going to need, then start writing your model code in run_model.

To learn about modelling with TRAC and what is possible, check out the modelling tutorials available in our online documentation. The tutorials are based on example models in the TRAC GitHub repository. We run these examples as part of our CI, so they will always be in sync with the corresponding version of the runtime library.

Building the runtime from source

This is not normally necessary for model development, but if you want to do it here are the commands.

cd trac-runtime/python

# Configure a Python environment

python -m venv ./venv
venv\Scripts\activate              # For Windows platforms
. venv/bin/activate                # For macOS or Linux
pip install -r requirements.txt

# Run the code generator

python ../../dev/codegen/protoc-ctrl.py python_runtime \
    --proto_path trac-api/trac-metadata/src/main/proto \
    --out trac-runtime/python/generated/trac/rt_gen/domain

# Build the Python package files

python ./package-ctrl.py

The package files will appear under build/dist

Project details


Download files

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

Source Distribution

trac-runtime-0.3.1.tar.gz (56.2 kB view details)

Uploaded Source

Built Distribution

trac_runtime-0.3.1-py3-none-any.whl (75.9 kB view details)

Uploaded Python 3

File details

Details for the file trac-runtime-0.3.1.tar.gz.

File metadata

  • Download URL: trac-runtime-0.3.1.tar.gz
  • Upload date:
  • Size: 56.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.2

File hashes

Hashes for trac-runtime-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e201fcca5525b41f984f80320e1bda0d764c33bff7ee266b01272e5a6720807c
MD5 5686e903daa3b750ff294b5c442a7623
BLAKE2b-256 c7921da342ac6878eeb68c8eeee440f656d533ede87077e34c2303be2fb76c23

See more details on using hashes here.

File details

Details for the file trac_runtime-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: trac_runtime-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 75.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.2

File hashes

Hashes for trac_runtime-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46a34c13c1dd715f8fd2d3cb1c79c78660dcf23d71f086075b01193ef194df9a
MD5 1988dc21ad09a9696ddaef27c7edfc83
BLAKE2b-256 024113f0158af72fee132cf84280118fbe2be208af3a5156cf23884a3c829a25

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