Skip to main content

Automate SAP with python!

Project description

Github - https://github.com/kamildemocko/PySapScript

SAP scripting for use in Python.
Can perform different actions in SAP GUI client on Windows.

Documentation

https://kamildemocko.github.io/PySapScript/

pdoc --html --output-dir docs .\src\pysapscript\

Installation

uv sync
uv pip install -e .

Usage

Create pysapscript object

import pysapscript

sapscript = pysapscript.Sapscript()

parameter default_window_title: = "SAP Easy Access"

Launch Sap

sapscript.launch_sap(
    sid="SQ4",
    client="012",
    user="robot_t",
    password=os.getenv("secret_password")
)

additional parameters:

root_sap_dir = Path(r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui")
maximise = True
language = "de"
quit_auto = True

Attach to an already opened window:

from pysapscript.window import Window

window: Window = sapscript.attach_window(0, 0)

positional parameters (0, 0) -> (connection, session)

Quitting SAP:

  • pysapscript will automatically quit if not manually specified in launch_sap parameter
  • manual quitting method: sapscript.quit()

Performing action:

element: use SAP path starting with wnd[0] for element arguments, for example wnd[0]/usr/txtMAX_SEL

  • element paths can be found by recording a sapscript with SAP GUI or by applications like SAP Script Tracker
window = sapscript.attach.window(0, 0)

window.maximize()
window.restore()
window.close()

window.start_transaction(value)
window.navigate(NavigateAction.enter)
window.navigate(NavigateAction.back)

window.write(element, value)
window.press(element)
window.send_v_key(value[, focus_element=True, value=0])
window.select(element)
selected = window.is_selected(element)
window.set_checkbox(value)
window.read(element)
window.visualize(element[, seconds=1])
window.exists(element)

window.set_dropdown(element, "02")
window.set_dropdown(element, "Excel File XLSX", value_type="text")

table: ShellTable = window.read_shell_table(element)
html_content = window.read_html_viewer(element)

Table actions

ShellTable uses polars, but can also be return pandas or dictionary

from pysapscript.shell_table import ShellTable

table: ShellTable = window.read_shell_table()

table.rows
table.columns

table.to_dict()
table.to_dicts()
table.to_polars_dataframe()
table.to_pandas_dataframe()

table.cell(row_value, col_value_or_name)
table.get_column_names()

table.load()
table.press_button(value)
table.select_rows([0, 1, 2])
table.select_row(1)
table.change_checkbox(element, value)

table.press_context_menu_item("%XXL")
table.press_context_menu_item("Excel File...", item_type="text")

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

pysapscript-3.4.0.tar.gz (101.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysapscript-3.4.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file pysapscript-3.4.0.tar.gz.

File metadata

  • Download URL: pysapscript-3.4.0.tar.gz
  • Upload date:
  • Size: 101.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for pysapscript-3.4.0.tar.gz
Algorithm Hash digest
SHA256 54f5db7f1382d9b77b5d5a037a59177200666c2814de7744bd75f9abf34079f8
MD5 9f9a2c739dea8ffadab1c906dd8691a7
BLAKE2b-256 2a9f034e10350ce73fc9da30f8375a7c5978f743b57cbf72861af11a6436be31

See more details on using hashes here.

File details

Details for the file pysapscript-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: pysapscript-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for pysapscript-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c699c76d3bbd778fb02dc94059048529d0d7c8956f7ed328541d5a29c0aa69f9
MD5 0f2ba433b51ecac8faedd356ff744286
BLAKE2b-256 7e58898297a7e840d0b8fa7f1e7b09174d39758840f21d4c7558979baeb1bd84

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page