Python Functions
These are example Python functions you can use as a starting point for developing your own code. Please be aware that these functions are not rigorously tested, so they should NOT be used for production purposes without further validation. They are provided purely as examples with no representation or warranty of any kind.
If there is a function you’d like to see an example of, please email us.
Data
| Function | Description |
|---|---|
| BASIC_CHART | Generates a matplotlib chart from 2D numeric data and returns a PNG image as a base64 string. |
| EXCHANGE_RATE | Retrieves the exchange rate from a base currency to a target currency using a public API. |
| INTERNET_CSV | Fetches a CSV file from the internet (with CORS proxy) and returns its contents as a 2D list. |
| ONEDRIVE_CSV | Retrieves a CSV file from the user’s Microsoft OneDrive App Folder using the Microsoft Graph API and a global variable graphToken for authentication. Returns the CSV contents as a 2D list, suitable for use in Excel. |
| SALESFORCE_APIS | Retrieves available Salesforce REST APIs and returns them as a 2D list. |
| WORDCLOUD | Generates a word cloud image from provided text data and returns a PNG image as a base64 string. |
Engineering
Fluids
Atmosphere
| Function | Description |
|---|---|
| AIRMASS | Calculate the mass of air per square meter in the atmosphere along a given angle using a density profile. |
| ATMOSPHERE_1976 | Calculate standard atmospheric properties at a given altitude using the US Standard Atmosphere 1976 model. |
| ATMOSPHERE_NRLMSISE00 | Compute temperature, density, and pressure using the NRLMSISE-00 atmospheric model. |
Control Valve
| Function | Description |
|---|---|
| CONTROL_VALVE_NOISE_G_2011 | Calculates the sound made by a gas flowing through a control valve according to the standard IEC 60534-8-3 (2011) using fluids.control_valve.control_valve_noise_g_2011. See https://fluids.readthedocs.io/fluids.control_valve.html#fluids.control_valve.control_valve_noise_g_2011 for details. |
| CONTROL_VALVE_NOISE_L_2015 | Calculates the sound made by a liquid flowing through a control valve according to the standard IEC 60534-8-4 (2015) using fluids.control_valve.control_valve_noise_l_2015. See https://fluids.readthedocs.io/fluids.control_valve.html#fluids.control_valve.control_valve_noise_l_2015 for details. |
| FF_CRITICAL_PRESSURE_RATIO_L | Calculates FF, the liquid critical pressure ratio factor, for use in IEC 60534 liquid valve sizing calculations using fluids.control_valve.FF_critical_pressure_ratio_l. See https://fluids.readthedocs.io/fluids.control_valve.html#fluids.control_valve.FF_critical_pressure_ratio_l for details. |
| SIZE_CONTROL_VALVE_G | Calculates flow coefficient of a control valve passing a gas according to IEC 60534 using fluids.control_valve.size_control_valve_g. See https://fluids.readthedocs.io/fluids.control_valve.html#fluids.control_valve.size_control_valve_g for details. |
| SIZE_CONTROL_VALVE_L | Calculates flow coefficient of a control valve passing a liquid according to IEC 60534 using fluids.control_valve.size_control_valve_l. See https://fluids.readthedocs.io/fluids.control_valve.html#fluids.control_valve.size_control_valve_l for details. |
Dimensionless
| Function | Description |
|---|---|
| ARCHIMEDES | Calculate the Archimedes number (Ar) for a fluid and particle. |
| BEJAN | Compute the Bejan number (length-based or permeability-based) using fluids.core library. |
| BOILING | Calculate the Boiling number (Bg), a dimensionless number for boiling heat transfer. |
| BOND | Calculate the Bond number (Bo), a dimensionless number comparing gravitational and surface tension forces. |
| CAPILLARY | Calculate the Capillary number (Ca) for a fluid system. |
| CAVITATION | Calculate the Cavitation number (Ca) for a flowing fluid. |
| CONFINEMENT | Calculate the Confinement number (Co) for two-phase flow in a channel. |
| DEAN | Calculate the Dean number (De) for flow in a curved pipe or channel. |
| DRAG | Calculate the drag coefficient (dimensionless) for an object in a fluid. |
| ECKERT | Calculate the Eckert number (Ec) for a given velocity, heat capacity, and temperature difference. |
| EULER | Calculate the Euler number (Eu) for a fluid flow. |
| FOURIER_HEAT | Calculate the Fourier number for heat transfer. |
| FOURIER_MASS | Calculate the Fourier number for mass transfer (Fo). |
| FROUDE | Calculate the Froude number (Fr) for a given velocity, length, and gravity. |
Photovoltaics
| Function | Description |
|---|---|
| CALCPARAMS_CEC | Calculate five CEC model parameters for the single diode equation at given irradiance and cell temperature. |
| CLEARSKY | Calculate clear sky GHI, DNI, and DHI for a location and time using PVLib. |
| I_FROM_V | Calculate the device current at a given device voltage for a PV cell/module using the single diode model. |
| IRRADIANCE | Calculate the plane of array irradiance components on a tilted surface using PVLib. |
| PVWATTS_DC | Calculate the DC power output of a PV module using the PVWatts DC model. |
| SOLARPOSITION | Calculate solar azimuth, elevation, and apparent zenith for given times and location. |
| Function | Description |
|---|---|
| PSYCHROMETRICS | Perform core psychrometric calculations: wet bulb, dew point, humidity ratio, enthalpy. |
| STRUCTURAL_FEA | Performs 3D finite element analysis using the Pynite package and returns support reactions. This function is provided as an example only without any representation or warranty of correctness. DO NOT rely on for production use without your own testing and validation. |
Financial
| Function | Description |
|---|---|
| BLACK_SCHOLES | Calculate the Black-Scholes price for a European call or put option. |
| GIFI_BAL | Assign GIFI asset codes to balance sheet row labels using an AI model. |
| PORTFOLIO_REBALANCER | Tax-efficient rebalancing of assets across Taxable, Roth, and Traditional accounts. |
| STOCK_PRICE | Retrieves the latest daily closing price for a given stock symbol using the Alpha Vantage API. |
Math
Interpolation
| Function | Description |
|---|---|
| BPOLY | Construct a piecewise polynomial in the Bernstein basis and evaluate it at specified points. |
| CUBIC_HERMITE_SPLINE | Piecewise cubic interpolation matching values and first derivatives at each point. |
| CUBIC_SPLINE | Perform cubic spline interpolation for 1D data. |
| GRIDDATA | Interpolate unstructured N-dimensional data using scipy.interpolate.griddata. |
| PPOLY | Construct and evaluate a piecewise polynomial in the power basis. |
Linear Algebra
| Function | Description |
|---|---|
| CHOLESKY | Compute the Cholesky decomposition of a real, symmetric positive-definite matrix. |
| EXPM | Compute the matrix exponential of a square matrix. |
| LSQ_LINEAR | Solve a bounded linear least-squares problem. |
| LSTSQ | Compute the least-squares solution to Ax = B using scipy.linalg.lstsq. |
| PINV | Compute the Moore-Penrose pseudoinverse of a matrix using singular value decomposition (SVD). |
| QR | Compute the QR decomposition of a matrix and return either Q or R. |
| SVD | Compute the Singular Value Decomposition (SVD) of a matrix using scipy.linalg.svd. |
Solvers
Calculus
Differentiation
| Function | Description |
|---|---|
| HESSIAN | Compute the Hessian matrix (second derivatives) of a scalar function using CasADi symbolic differentiation. |
| JACOBIAN | Calculate the Jacobian matrix of mathematical expressions with respect to specified variables. |
| SENSITIVITY | Compute the sensitivity of a scalar model with respect to its parameters using CasADi. |
Integration
| Function | Description |
|---|---|
| DBLQUAD | Compute the double integral of a function over a two-dimensional region. |
| QUAD | Numerically integrate a function defined by a table of x, y values over [a, b] using adaptive quadrature. |
| TRAPEZOID | Integrate sampled data using the composite trapezoidal rule. |
ODE Models
| Function | Description |
|---|---|
| BRUSSELATOR | Numerically solves the Brusselator system of ordinary differential equations for |
| COMPARTMENTAL_PK | Numerically solves the basic compartmental pharmacokinetics system of ordinary differential equations. |
| FITZHUGH_NAGUMO | Wrapper around scipy.integrate.solve_ivp that numerically solves the FitzHugh-Nagumo system of |
| HODGKIN_HUXLEY | Numerically solves the Hodgkin-Huxley system of ordinary differential equations for neuron action potentials. |
| LORENZ | Numerically solves the Lorenz system of ordinary differential equations for chaotic dynamics. |
| LOTKA_VOLTERRA | Numerically solves the Lotka-Volterra predator-prey system of ordinary differential equations. |
| MICHAELIS_MENTEN | Numerically solves the Michaelis-Menten system of ordinary differential equations for enzyme kinetics. |
| SEIR | Numerically solves the SEIR system of ordinary differential equations for infectious disease modeling. |
| SIR | Solves the SIR system of ordinary differential equations for infection dynamics. |
| VAN_DER_POL | Numerically solves the Van der Pol oscillator system of ordinary differential equations. |
ODE Systems
| Function | Description |
|---|---|
| SOLVE_BVP | Solve a boundary value problem for a second-order system of ODEs. |
| SOLVE_IVP | Solve an initial value problem for a system of ODEs of the form dy/dt = A @ y. |
Optimization
Assignment Problems
| Function | Description |
|---|---|
| LINEAR_ASSIGNMENT | Solve the linear assignment problem using scipy.optimize.linear_sum_assignment. |
| QUADRATIC_ASSIGNMENT | Solve a quadratic assignment problem using SciPy’s implementation. |
Curve Fitting
| Function | Description |
|---|---|
| CURVE_FIT | Fit a model specified by model_id to xdata, ydata using scipy.optimize.curve_fit. |
Global Optimization
| Function | Description |
|---|---|
| BASIN_HOPPING | Minimize a single-variable expression with SciPy’s basinhopping algorithm. |
| BRUTE | Perform a brute-force grid search to approximate the global minimum of a function. |
| DIFFERENTIAL_EVOLUTION | Minimize a multivariate function using differential evolution. |
| DUAL_ANNEALING | Minimize a multivariate function using dual annealing. |
| SHGO | Find global minimum using Simplicial Homology Global Optimization. |
Linear Programming
| Function | Description |
|---|---|
| LINEAR_PROG | Solve a linear programming problem using SciPy’s linprog. |
| MILP | Solve a mixed-integer linear program using scipy.optimize.milp. |
Local Optimization
| Function | Description |
|---|---|
| MINIMIZE | Minimize a multivariate function using SciPy’s minimize routine. |
| MINIMIZE_SCALAR | Minimize a single-variable function using SciPy’s minimize_scalar. |
Root Finding
| Function | Description |
|---|---|
| FIXED_POINT | Find a fixed point x such that f(x) = x for a scalar function expression. |
| ROOT | Solve a square nonlinear system using SciPy’s root solver. |
| ROOT_SCALAR | Find a real root of a scalar function using SciPy’s root_scalar. |
Stats
Frequency Statistics
| Function | Description |
|---|---|
| BINNED_STATISTIC | Computes a binned statistic (mean, sum, median, etc.) for the input data. |
| BINNED_STATISTIC_2D | Computes a bidimensional binned statistic (mean, sum, median, etc.) for the input data. |
| CUMFREQ | Returns the cumulative frequency histogram for the input data. |
| PERCENTILEOFSCORE | Computes the percentile rank of a score relative to the input data. |
| RELFREQ | Returns the relative frequency histogram for the input data. |
| SCOREATPERCENTILE | Calculates the score at the given percentile of the input data. |
Hypothesis Tests
Association Correlation
| Function | Description |
|---|---|
| BARNARD_EXACT | Perform Barnard’s exact test on a 2x2 contingency table. |
| BOSCHLOO_EXACT | Perform Boschloo’s exact test on a 2x2 contingency table. |
| CHI2_CONTINGENCY | Perform the chi-square test of independence for variables in a contingency table. |
| FISHER_EXACT | Perform Fisher’s exact test on a contingency table. |
| KENDALLTAU | Calculate Kendall’s tau, a correlation measure for ordinal data. |
| PAGE_TREND_TEST | Perform Page’s L trend test for monotonic trends across treatments. |
| PEARSONR | Calculate the Pearson correlation coefficient and p-value for two datasets. |
| POINTBISERIALR | Calculate a point biserial correlation coefficient and its p-value. |
| SIEGELSLOPES | Compute the Siegel repeated medians estimator for robust linear regression. |
| SOMERSD | Calculate Somers’ D, an asymmetric measure of ordinal association between two variables. |
| SPEARMANR | Calculate a Spearman correlation coefficient with associated p-value. |
| THEILSLOPES | Compute the Theil-Sen estimator for a set of points (robust linear regression). |
| WEIGHTEDTAU | Compute a weighted version of Kendall’s tau correlation coefficient. |
Independent Sample
| Function | Description |
|---|---|
| ALEXANDERGOVERN | Performs the Alexander-Govern test for equality of means across multiple independent samples with possible heterogeneity of variance. |
| ANDERSON_KSAMP | Performs the k-sample Anderson-Darling test to determine if samples are drawn from the same population. |
| ANSARI | Performs the Ansari-Bradley test for equal scale parameters (non-parametric). |
| BRUNNERMUNZEL | Computes the Brunner-Munzel nonparametric test for two independent samples. |
| BWS_TEST | Performs the Baumgartner-Weiss-Schindler test on two independent samples. |
| CRAMERVONMISES_2SAMP | Performs the two-sample Cramér-von Mises test for goodness of fit between two independent samples. |
| DUNNETT | Performs Dunnett’s test for multiple comparisons of means against a control group. |
| EPPS_SINGLETON_2SAMP | Computes the Epps-Singleton test statistic and p-value for two samples. |
| F_ONEWAY | Performs a one-way ANOVA test for two or more independent samples. |
| FLIGNER | Performs the Fligner-Killeen test for equality of variances across multiple samples. |
| FRIEDMANCHISQUARE | Computes the Friedman test for repeated samples. |
| KRUSKAL | Computes the Kruskal-Wallis H-test for independent samples. |
| KS_2SAMP | Performs the two-sample Kolmogorov-Smirnov test for goodness of fit. |
| KSTEST | Performs the Kolmogorov-Smirnov test for goodness of fit between two samples or a sample and a reference distribution. |
| LEVENE | Performs the Levene test for equality of variances across multiple samples. |
| MANNWHITNEYU | Performs the Mann-Whitney U rank test on two independent samples. |
| MEDIAN_TEST | Performs Mood’s median test to determine if two or more independent samples come from populations with the same median. |
| MOOD | Performs Mood’s two-sample test for scale parameters (non-parametric). |
| POISSON_MEANS_TEST | Performs the Poisson means test (E-test) to compare the means of two Poisson distributions. |
| RANKSUMS | Computes the Wilcoxon rank-sum statistic and p-value for two independent samples. |
| TTEST_IND | Performs the independent two-sample t-test for the means of two groups. |
| TTEST_IND_FROM_STATS | Performs a t-test for means of two independent samples using summary statistics. |
| TUKEY_HSD | Performs Tukey’s HSD test for equality of means over multiple treatments. |
One Sample
| Function | Description |
|---|---|
| BINOMTEST | Perform a binomial test for the probability of success in a Bernoulli experiment. |
| JARQUE_BERA | Perform the Jarque-Bera goodness of fit test for normality. |
| KURTOSISTEST | Test whether the kurtosis of a sample is different from that of a normal distribution. |
| NORMALTEST | Test whether a sample differs from a normal distribution (omnibus test). |
| QUANTILE_TEST | Perform a quantile test and compute a confidence interval of the quantile. |
| SHAPIRO | Perform the Shapiro-Wilk test for normality. |
| SKEWTEST | Test whether the skewness of a sample is different from that of a normal distribution. |
Paired Sample
| Function | Description |
|---|---|
| TTEST_1SAMP | Perform a one-sample t-test for the mean of a group of scores. |
Misc
| Function | Description |
|---|---|
| DENDROGRAM | Performs hierarchical (agglomerative) clustering on numeric data and returns a dendrogram as a base64-encoded PNG image or an error message. |
| VAL_DISCRETE | Select a value from a list based on a discrete probability distribution. |
Probability Distributions
Continuous Distributions
| Function | Description |
|---|---|
| BETA | Generalized Beta distribution function supporting multiple methods. |
| CAUCHY | Cauchy distribution function supporting multiple methods. |
| CHISQ | Chi-squared distribution function supporting multiple methods. |
| EXPON | Exponential distribution function supporting multiple methods. |
| F_DIST | Unified interface to the main methods of the F-distribution, including PDF, CDF, inverse CDF, survival function, and distribution statistics. |
| LAPLACE | Laplace distribution function supporting multiple methods. |
| LOGNORM | Generalized lognormal distribution function supporting multiple methods. |
| NORM | Normal (Gaussian) distribution function supporting multiple methods. |
| PARETO | Generalized Pareto distribution function supporting multiple methods. |
| T_DIST | Student’s t distribution function supporting multiple methods. |
| UNIFORM | Uniform distribution function supporting multiple methods. |
| WEIBULL_MIN | Weibull minimum distribution function supporting multiple methods. |
Discrete Distributions
| Function | Description |
|---|---|
| BERNOULLI | Calculates properties of a Bernoulli discrete random variable. |
| BETABINOM | Compute Beta-binomial distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| BETANBINOM | Compute Beta-negative-binomial distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| BINOM | Compute Binomial distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| BOLTZMANN | Compute Boltzmann distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| DLAPLACE | Compute Discrete Laplace distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| GEOM | Compute Geometric distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| HYPERGEOM | Compute Hypergeometric distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| LOGSER | Compute Log-Series distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| NBINOM | Compute Negative Binomial distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| NHYPERGEOM | Compute Negative Hypergeometric distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| PLANCK | Compute Planck distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| POISSON_DIST | Compute Poisson distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| RANDINT | Compute Uniform discrete distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| SKELLAM | Compute Skellam distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| YULESIMON | Compute Yule-Simon distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| ZIPF | Compute Zipf distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
| ZIPFIAN | Compute Zipfian distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. |
Multivariate Distributions
| Function | Description |
|---|---|
| DIRICHLET | Computes the PDF, log-PDF, mean, variance, covariance, entropy, or draws random samples from a Dirichlet distribution. |
| DIRICHLET_MULTINOMIAL | Computes the probability mass function, log probability mass function, mean, variance, or covariance of the Dirichlet multinomial distribution. |
| MATRIX_NORMAL | Computes the PDF, log-PDF, or draws random samples from a matrix normal distribution. |
| MULTINOMIAL | Computes the probability mass function, log-PMF, entropy, covariance, or draws random samples from a multinomial distribution. |
| MULTIVARIATE_HYPERGEOM | Computes probability mass function, log-PMF, mean, variance, covariance, or draws random samples from a multivariate hypergeometric distribution. |
| MULTIVARIATE_NORMAL | Computes the PDF, CDF, log-PDF, log-CDF, entropy, or draws random samples from a multivariate normal distribution. |
| MULTIVARIATE_T | Computes the PDF, CDF, or draws random samples from a multivariate t-distribution. |
| ORTHO_GROUP | Draws random samples of orthogonal matrices from the O(N) Haar distribution. |
| RANDOM_CORRELATION | Generates a random correlation matrix with specified eigenvalues. |
| SPECIAL_ORTHO_GROUP | Draws random samples from the special orthogonal group SO(N), returning orthogonal matrices with determinant +1. |
| UNIFORM_DIRECTION | Draws random unit vectors uniformly distributed on the surface of a hypersphere in the specified dimension. |
| UNITARY_GROUP | Generates a random unitary matrix of dimension N. |
| VONMISES_FISHER | Computes the PDF, log-PDF, entropy, or draws random samples from a von Mises-Fisher distribution on the unit hypersphere. |
| WISHART | Computes the PDF, log-PDF, or draws random samples from a Wishart distribution. |
Summary Statistics
| Function | Description |
|---|---|
| DESCRIBE | Compute descriptive statistics using scipy.stats.describe module. |
| EXPECTILE | Calculates the expectile of a dataset. |
| GMEAN | Compute the geometric mean of the input data, flattening the input and ignoring non-numeric values. |
| HMEAN | Calculates the harmonic mean of the input data. |
| KURTOSIS | Computes the kurtosis (Fisher or Pearson) of a dataset. |
| MODE | Returns the modal (most common) value in the passed array. Flattens the input, ignores non-numeric values, and always returns a single mode (the smallest if multiple). If no mode is found, returns “No mode found”. |
| MOMENT | Calculates the nth moment about the mean for a sample. |
| PMEAN | Computes the power mean (generalized mean) of the input data for a given power p. |
| SKEWNESS | Calculate the skewness of a dataset. |
Text
| Function | Description |
|---|---|
| AI_ASK | Generate a text response using an AI model based on a prompt and optional tabular data. |
| AI_CHOICE | Uses AI to select the most appropriate choice from a list of options based on the given context. |
| AI_EXTRACT | Uses an AI model to extract specific types of information from unstructured text. |
| AI_FILL | Fills missing or incomplete data in a target range by learning patterns from an example range using a large language model. |
| AI_FORMAT | Uses an AI model to format text according to a specific structure or pattern. |
| AI_LIST | Generate a list of items using an AI model based on a prompt and optional context values. |
| AI_TABLE | Uses an AI model to generate a structured table (2D list) based on a prompt, with optional header and source data. |
| JINA_READER | Returns web page content in markdown format using Jina. Useful as a starting point for extraction, summarization, etc. |
| TEXT_DISTANCE | Calculate text similarity scores between lookup_value(s) and lookup_array items using the specified algorithm. |
| VADER_SENTIMENT | Analyze sentiment of text using VADER. |
Last updated on