Skip to main content

Python Snap7 Easy Vars

A Python wrapper for the snap7 PLC communication library with easy variable management. This library simplifies reading and writing variables to Siemens PLCs using snap7 by allowing users to define data structures that map directly to PLC data blocks. It wraps around the python-snap7 library and provides an easy-to-use interface for defining PLC variables, reading from, and writing to the PLC.

Quick Start

Install the package via pip:

pip install python-snap7-easy-vars

Import the library and create a data structure:

import snap7_easy_vars

class MyPLCData(snap7_easy_vars.PLCData):
    # Define PLC variables with their data types and offsets
    temperature = snap7_easy_vars.PLCRealField(byte_offset=0) 
    pressure = snap7_easy_vars.PLCWordField(byte_offset=4)

    # By default, fields are read-only; to make a field settable, use the 'settable' parameter
    status = snap7_easy_vars.PLCBoolField(byte_offset=6, bit_offset=0, settable=True)

Connect to the PLC and read/write data:

my_plc_data = MyPLCData()
my_plc_connection = snap7_easy_vars.PLCConnection(
    ip_address="192.168.0.1", # PLC IP address
    data_store=my_plc_data,
    db_number=1, # PLC DB number
    rack=0, # PLC rack number
    slot=1, # PLC slot number
    port=102, # PLC port number
)

# Connect to the PLC
my_plc_connection.connect()

# Read data from the PLC
my_plc_connection.read()

# Read variables
print(f"Temperature: {my_plc_data.temperature}")
print(f"Pressure: {my_plc_data.pressure}")
print(f"Status: {my_plc_data.status}")

# Modify a variable and write back to the PLC
my_plc_data.status = True
my_plc_connection.write()

Authors

Metadata

Release files for python-snap7-easy-vars 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-snap7-easy-vars 1.0.4
File Size Uploaded
python_snap7_easy_vars-1.0.4.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-snap7-easy-vars 1.0.4
File Interpreter ABI Platform
python_snap7_easy_vars-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 12.9 kB

Release files / python_snap7_easy_vars-1.0.4.tar.gz

Download URL python_snap7_easy_vars-1.0.4.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
052b4e7b48259c4709131d12a0f6945eb5f8bded5857c0ad8250bce80aa64397
BLAKE2b-256 checksum
How to use checksums
8d5ecbdb39f8a33dc03d409213ba27cbbcdff4c8576c5a3c59d99819754c69f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Release files / python_snap7_easy_vars-1.0.4-py3-none-any.whl

Download URL python_snap7_easy_vars-1.0.4-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e229ee2b1d06f9c7244199891c1d8785be53145a28489471d0f99542ccbd9d95
BLAKE2b-256 checksum
How to use checksums
6b882f2e4990414aba80672ce5f9624cc31917e486129a253903c222cefb39d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page