Interact with the Nema data collaboration platform
Project description
Nema Python Extension
This library provides a set of classes and functions to work with Nema artifacts.
It provides both the nema library, as well as the nema-python CLI.
Installation
To install the Nema Python extension, run the following command (you'll likely want to do this in a virtual environment):
pip install nema
This installs both the nema python package and the nema-python CLI tool.
Nema works for Python 3.8 and above.
Usage
To login into Nema, run nema-python login from the command line. This will prompt you to enter your Nema credentials.
Then run nema-python init which will prompt you for your Nema project URL and create a nema.toml file in your current directory.
Workflows
nema-python workflow init will then create a workflow in Nema.
You can then create the actual code that you want to run, for example:
from nema.data.data_properties import IntegerValue, ArbitraryFile
from nema.data.tabular.tabular_data_properties import CSVData
from nema.data.plots.figure_data_properties import Image
from nema.run import workflow
import pandas as pd
import numpy as np
from dataclasses import dataclass
import matplotlib.pyplot as plt
@dataclass
class Inputs:
integer_1: IntegerValue
integer_2: IntegerValue
arbitrary_file: ArbitraryFile
@dataclass
class Output:
result_table: CSVData
result_data: IntegerValue
image_result: Image
@workflow(
input_global_id_mapping={ # this is the mapping of the input data to the global IDs (in the Nema project)
# if they're 0, Nema will create the artifacts for you
"integer_1": 0,
"integer_2": 0,
"arbitrary_file": 0,
},
output_global_id_mapping={ # this is the mapping of the output data to the global IDs (in the Nema project)
"result_table": 0,
"image_result": 0,
"result_data": 0,
},
)
def run(inputs: Inputs) -> Output: # this needs to be called `run` for the workflow to work
result_value = IntegerValue(inputs.integer_1.value * inputs.integer_2.value)
# output a table
resulting_table = pd.DataFrame(
{
"test_data_1": [inputs.integer_1.value],
"test_data_2": [inputs.integer_2.value],
"result": [result_value.value],
}
)
result_table = CSVData(df=resulting_table)
# Create a simple plot
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y, label="Sine Wave")
plt.title("Simple Sine Wave")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.legend()
plot_output = Image()
plt.savefig(plot_output.get_file_name_to_save())
# Read in an arbitrary file
with inputs.arbitrary_file("r") as f:
print(f.read())
return Output(
result_table=result_table, result_data=result_value, image_result=plot_output
)
To run this workflow locally and upload the results to Nema, run nema-python workflow run.
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 nema-0.1.14.tar.gz.
File metadata
- Download URL: nema-0.1.14.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
128e2e36de6ee88916282657cfea7720dbe15d54fef1f5a069332e1073fadfd2
|
|
| MD5 |
4a8c3322245b2bb0d15114ad5a7b5f63
|
|
| BLAKE2b-256 |
03c01dea106422aa32e4ad3fe663fed48c940c24706927855dde12e5c0f4c062
|
Provenance
The following attestation bundles were made for nema-0.1.14.tar.gz:
Publisher:
extensions_python.yml on nema-systems/nema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nema-0.1.14.tar.gz -
Subject digest:
128e2e36de6ee88916282657cfea7720dbe15d54fef1f5a069332e1073fadfd2 - Sigstore transparency entry: 346544593
- Sigstore integration time:
-
Permalink:
nema-systems/nema@dd82fa6d75e5668166409f42c4445c694cfafd4b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/nema-systems
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
extensions_python.yml@dd82fa6d75e5668166409f42c4445c694cfafd4b -
Trigger Event:
push
-
Statement type:
File details
Details for the file nema-0.1.14-py3-none-any.whl.
File metadata
- Download URL: nema-0.1.14-py3-none-any.whl
- Upload date:
- Size: 31.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba57e3e6987eabdccf5181a0e2667c0fd544bb7dab6f2251f62f57189b8a709a
|
|
| MD5 |
a4801891ad8e4889a953ebba83e37f78
|
|
| BLAKE2b-256 |
2482d117c7ce06c9c125745970a5c6433f0b6ae80000ddb280263b91273ef822
|
Provenance
The following attestation bundles were made for nema-0.1.14-py3-none-any.whl:
Publisher:
extensions_python.yml on nema-systems/nema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nema-0.1.14-py3-none-any.whl -
Subject digest:
ba57e3e6987eabdccf5181a0e2667c0fd544bb7dab6f2251f62f57189b8a709a - Sigstore transparency entry: 346544608
- Sigstore integration time:
-
Permalink:
nema-systems/nema@dd82fa6d75e5668166409f42c4445c694cfafd4b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/nema-systems
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
extensions_python.yml@dd82fa6d75e5668166409f42c4445c694cfafd4b -
Trigger Event:
push
-
Statement type: