An extension for TRAC D.A.P. that lets models connect to HTTP endpoints
Project description
HTTP Extension for the TRAC Model Runtime
This extension allows TRAC models to make calls to external systems using HTTP and HTTPS.
- Make HTTP endpoints available to models, to use directly in model code
- Connection settings managed by TRAC for both local and deployed models
- Supports http.client and urllib3
Models that make external calls are not considered repeatable, and will be flagged as not repeatable when they run on the TRAC platform.
This extension is a pre-release and will be finalized inTRAC 0.10.
Installing
The HTTP extension can be installed with pip:
$ pip install tracdap-ext-http
The package has the following dependencies:
- tracdap-runtime (version 0.10.0-beta1 or later)
- urllib3 (optional, version 2.x)
Using the http.client API
Here is a minimum working example of a TRAC model using the http.client API:
import tracdap.rt.api as trac
import http.client as hc
class TestModel(trac.TracModel):
# ... define parameters, inputs and outputs
def define_resources(self):
return {
"github": trac.define_external_system("http", hc.HTTPSConnection)
}
def run_model(self, ctx: trac.TracContext):
with ctx.get_external_system("github", hc.HTTPSConnection) as github:
github.connect()
github.request("GET", "finos/tracdap/refs/heads/main/README.md")
response = github.getresponse()
response_text = response.read().decode("utf-8")
first_line = response_text.splitlines()[0]
ctx.log.info(first_line)
if __name__ == '__main__':
import tracdap.rt.launch as launch
launch.launch_model(TestModel, "config/job_config.yaml", "config/sys_config.yaml")
To make this example work, you will need to add github as a resource in the system config file:
resources:
github:
resourceType: EXTERNAL_SYSTEM
protocol: http
properties:
host: raw.githubusercontent.com
port: 443
tls: true
The following configuration properties are supported:
- host, string, required
- port, int, optional
- tls, bool, default = true
- timeout, float, optional
Models using the client type HTTPSConnection will only work if tls = true is set in the configuration.
Models requesting HTTPConnection will work with tls = true or tls = false,
and will receive an HTTPSConnection if tls = true.
Using the urllib3 API
Here is a minimum working example of a TRAC model using the urllib3 API. In order to use this API, the urllib3 package must be installed.
import tracdap.rt.api as trac
import urllib3
class TestModel(trac.TracModel):
# ... define parameters, inputs and outputs
def define_resources(self):
return {
"github": trac.define_external_system("http", urllib3.HTTPSConnectionPool)
}
def run_model(self, ctx: trac.TracContext):
with ctx.get_external_system("github", urllib3.HTTPSConnectionPool, timeout=10.0) as github:
response = github.request("GET", "/finos/tracdap/refs/heads/main/README.md")
response_text = response.data.decode("utf-8")
first_line = response_text.splitlines()[0]
ctx.log.info(first_line)
if __name__ == '__main__':
import tracdap.rt.launch as launch
launch.launch_model(TestModel, "config/job_config.yaml", "config/sys_config.yaml")
The resource configuration for the urllib3 API is identical to the http.client API.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tracdap_ext_http-0.10.0.dev0.tar.gz.
File metadata
- Download URL: tracdap_ext_http-0.10.0.dev0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4f203353578d1584b7856611e8611d631acd6ba1c3ec230ea383a3dc335a0ab
|
|
| MD5 |
1c30502c908ee1725ffa3c72cde2d098
|
|
| BLAKE2b-256 |
486dc5991e2197c9bb2e4577e403b27a102abb954320eba14e2e1784fa113491
|
Provenance
The following attestation bundles were made for tracdap_ext_http-0.10.0.dev0.tar.gz:
Publisher:
packaging.yaml on martin-traverse/tracdap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tracdap_ext_http-0.10.0.dev0.tar.gz -
Subject digest:
e4f203353578d1584b7856611e8611d631acd6ba1c3ec230ea383a3dc335a0ab - Sigstore transparency entry: 500152196
- Sigstore integration time:
-
Permalink:
martin-traverse/tracdap@8ba03e353b6d9ac38df91d3c5f980a5aa8c6f571 -
Branch / Tag:
refs/tags/0.10.0-dev.19 - Owner: https://github.com/martin-traverse
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
packaging.yaml@8ba03e353b6d9ac38df91d3c5f980a5aa8c6f571 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tracdap_ext_http-0.10.0.dev0-py3-none-any.whl.
File metadata
- Download URL: tracdap_ext_http-0.10.0.dev0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88371c78f7a0bff41815c9de89e81325f9176d9c70599db3ae306a6b91190caf
|
|
| MD5 |
dd250879f3e844e92371035d029b3745
|
|
| BLAKE2b-256 |
9435c2e1bb249d0060ea450dc4bfdeb53cb7f4d476cb4bef7be4961fbb9f4d22
|
Provenance
The following attestation bundles were made for tracdap_ext_http-0.10.0.dev0-py3-none-any.whl:
Publisher:
packaging.yaml on martin-traverse/tracdap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tracdap_ext_http-0.10.0.dev0-py3-none-any.whl -
Subject digest:
88371c78f7a0bff41815c9de89e81325f9176d9c70599db3ae306a6b91190caf - Sigstore transparency entry: 500152218
- Sigstore integration time:
-
Permalink:
martin-traverse/tracdap@8ba03e353b6d9ac38df91d3c5f980a5aa8c6f571 -
Branch / Tag:
refs/tags/0.10.0-dev.19 - Owner: https://github.com/martin-traverse
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
packaging.yaml@8ba03e353b6d9ac38df91d3c5f980a5aa8c6f571 -
Trigger Event:
release
-
Statement type: