xl-engine
Use your existing Excel workbooks like they were Python programs: A utility built on XLWings to automate the input, execution, and data retrieval of your existing Excel Workbooks.
Installation
pip install xl-engine
Basic Usage
execute_workbook
Use execute_workbook when you want to execute a workbook once with known, provided parameters.
import xl_engine as xl
results = xl.execute_workbook(
TEST_DATA_DIR / "example_wb.xlsx",
cells_to_change = {"B1": 33, "B2": 66},
cells_to_retrieve=['B4', 'B5'], # This can either be a list or a dict; see next example
sheet_idx=1,
new_filepath=TEST_DATA_DIR / "stored_results.xlsx"
)
# results
# {'B4': 22.0, 'B5': 11.0}
You can also use a dictionary in cells_to_retrieve to meaningfully label the results:
results2 = xl.execute_workbook(
TEST_DATA_DIR / "example_wb.xlsx",
cells_to_change = {"B1": 33, "B2": 66},
cells_to_retrieve={'B4': "label1", 'B5': "label2"}, # Now a dict
sheet_idx=1,
new_filepath=TEST_DATA_DIR / "stored_results.xlsx"
)
# results2
# {'label1': 44.0, 'label2': 39.599999999999994}
excel_runner
Use excel_runner when you want to execute a workbook multiple times (static inputs) with multiple options (dynamic inputs).
import xl_engine as xl
# Creates a callable with the following function signature: callable(x: float | int) -> bool:
# When a value is a passed to dcr2, i.e. dcr2(some_value), it will return True if
# the value is greater-than-or-equal-to 2
dcr2 = xl.create_condition_check(2, "ge")
# static_inputs will be used to populate each workbook.
# Within each set of static inputs, a second sub-iteration will occur
# where the dynamic inputs will be input allowing you to test the
# results for different "options" of dynamic inputs.
# If the save conditions pass (return True for all keys), then a copy of the
# workbook will be saved to disk with the successful inputs recorded.
# A dictionary of all calculated results will be returned.
results = xl.excel_runner(
TEST_DATA_DIR / "example_wb.xlsx",
static_inputs={"B1": [10, 20], "Labels": ["C01", "C02"]},
dynamic_inputs={
"OptA": {"B2": 22},
"OptB": {"B2": 33},
"OptC": {"B2": 55},
},
success_conditions={"B6": dcr2},
static_identifier_keys=["Labels"],
result_labels={"B6": "meaningful_value"},
save_dir=TEST_DATA_DIR / "design"
)
Return value (for the "example_wb.xlsx" file included in the tests directory):
{
'C01': {
'successful_key': None, # None of the options were successful for this case
'OptA': {'meaningful_value': 1.2121212121212122},
'OptB': {'meaningful_value': 0.8080808080808081},
'OptC': {'meaningful_value': 0.48484848484848486}
},
'C02': {
'successful_key': 'OptA',
'meaningful_value': 2.4242424242424243
}
}
Metadata
Release files for xl-engine 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| xl_engine-0.4.0.tar.gz | 60.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xl_engine-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 71.2 kB
Release files / xl_engine-0.4.0.tar.gz
| Download URL | xl_engine-0.4.0.tar.gz |
|---|---|
| Size | 60.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9dabc2eec7c4c8c2be55ca562a30a8f5f75db81af2930ff3ff3c28f5614597a
|
|
BLAKE2b-256 checksum How to use checksums |
5e1bb3e33aad2e249b8acbdd6c5f49162ad88798fbf1b2510ed88f29d328e5c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|
Release files / xl_engine-0.4.0-py3-none-any.whl
| Download URL | xl_engine-0.4.0-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf2b6eb1ec31ac46b8b54831dae7a7b067a955c93342fc2a791dd284a2ebb5f9
|
|
BLAKE2b-256 checksum How to use checksums |
a8055385ef8ea7437857e0ff78d534aae4628a114f9b06a7963184732713e7a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|
Security for xl-engine 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.