Skip to main content

Pure-python library for Fermilab control system

Project description

pacsys

Pure-Python library for Fermilab's control system.

Tests Documentation License: GPL-3.0 Python 3.10+

About

ACNET (Accelerator Control NETwork) is the control system used at Fermilab's particle accelerators. PACSys provides a simple Python interface to interact with ACNET data without needing to understand the underlying protocols.

Features

  • Read/Write/Stream any ACNET data types with synchronous or async APIs
  • Multiple backends to connect to DPM, DMQ, and ACL
  • Full DRF3 parser for data requests with automatic conversion
  • Utilities for device database, SSH tunneling, and more
  • Command-line tools like in EPICS - acget, acput, acmonitor, acinfo

Installation

pip install pacsys

Device API (recommended)

import pacsys
from pacsys import Device, Verify, KerberosAuth

# Create a device -- DRF is validated immediately
dev = Device("M:OUTTMP")

# Read different properties
temperature = dev.read()               # READING (scaled value)
setpoint = dev.setting()               # SETTING property
is_on = dev.status(field="on")         # STATUS field ON
alarm = dev.analog_alarm()             # ANALOG alarm

# Full reading with metadata
reading = dev.get()
print(f"{reading.value} {reading.units}")  # e.g. "72.5 DegF"

# Write with automatic readback verification
result = dev.write(72.5, verify=Verify(tolerance=0.5))
assert result.verified

# Control commands with shortcuts
dev.on()
dev.off()
dev.reset()

# Device database metadata (scaling, limits, units)
info = dev.info()
print(info.description)                # "Outside temperature"
print(info.reading.common_units)       # "DegF"
print(info.reading.min_val)            # 0.0

# Stream data
with dev.with_event("p,1000").subscribe() as stream:
    for reading, handle in stream.readings(timeout=10):
        print(reading.value)

# Immutable -- modifications return new instances
periodic_dev = dev.with_event("p,1000")
sliced_dev = dev.with_range(0, 10)

Backend API

import time
import pacsys

# Read a device value through global backend
temperature = pacsys.read("M:OUTTMP")
print(f"Temperature: {temperature}")

# Stream real-time data through global backend
with pacsys.subscribe(["M:OUTTMP@p,1000"]) as stream:
    for reading, handle in stream.readings(timeout=30):
        print(f"{reading.name}: {reading.value}")

# Stream with callback dispatch mode through dedicated DPM instance
# WORKER (default): callbacks on dedicated worker thread, protects event loop
# DIRECT: callbacks inline on reactor thread (lower latency)
with pacsys.dpm(dispatch_mode=pacsys.DispatchMode.DIRECT) as backend:
    handle = backend.subscribe(
        ["M:OUTTMP@p,1000"],
        callback=lambda r, h: print(r.value),
    )
    time.sleep(10)
    handle.stop()

# Write through authenticated DPM instance (requires kerberos ticket)
with pacsys.dpm(auth=pacsys.KerberosAuth(), role="testing") as backend:
    backend.write("Z:ACLTST", 72.5)

Async capabilities

Native async versions with same API surface.

import pacsys.aio as aio

# Module-level API (mirrors pacsys.read, pacsys.get, etc.)
value = await aio.read("M:OUTTMP")
reading = await aio.get("M:OUTTMP")

# Explicit async backend
async with aio.dpm(auth=pacsys.KerberosAuth()) as backend:
    await backend.write("Z:ACLTST", 72.5)

# Async streaming
async with await backend.subscribe(["M:OUTTMP@p,1000"]) as stream:
    async for reading, handle in stream.readings(timeout=30):
        print(f"{reading.name}: {reading.value}")

# AsyncDevice
from pacsys.aio import AsyncDevice

dev = AsyncDevice("M:OUTTMP", backend=backend)
temp = await dev.read()
await dev.on()

SSH Utilities

Port tunneling, SFTP, and interactive processes over multi-hop SSH.

import pacsys

# Execute commands with automatic Kerberos auth
with pacsys.ssh(["jump.fnal.gov", "target.fnal.gov"]) as ssh:
    result = ssh.exec("hostname")
    print(result.stdout) # target

# ACL can be run on the fly - beam switch, DB, etc.
with pacsys.ssh("clx01.fnal.gov") as ssh:
    result = ssh.acl("read M:OUTTMP") # "M:OUTTMP       =  72.500 DegF"

CLI Tools

EPICS-style command-line tools:

# Read devices
acget M:OUTTMP Z:ACLTST
acget --format json M:OUTTMP

# Write devices (requires authentication, kerberos attempted by default)
acput Z:ACLTST 72.5
acput -a kerberos -b dmq --verify --tolerance 0.5 Z:ACLTST 72.5

# Monitor (streaming on default event or custom one)
acmonitor M:OUTTMP
acmonitor -n 10 M:OUTTMP@p,500

# Device info (DB + property reads)
acinfo -v M:OUTTMP

Also aliased under pacsys-get, pacsys-put, pacsys-monitor, pacsys-info.

Requirements

  • Python 3.10+
  • For writes: Kerberos credentials with appropriate role or console class assigned
  • For some utilities: must run on the controls network or have SSH access to it

Documentation

See the full documentation for guides, API reference, and protocol details.

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

pacsys-0.2.1.tar.gz (393.5 kB view details)

Uploaded Source

Built Distribution

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

pacsys-0.2.1-py3-none-any.whl (292.0 kB view details)

Uploaded Python 3

File details

Details for the file pacsys-0.2.1.tar.gz.

File metadata

  • Download URL: pacsys-0.2.1.tar.gz
  • Upload date:
  • Size: 393.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pacsys-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d51c90c3240f1b306f25fb1bdbd968429fc96c11e9e4b8700e9d3dd5c0470d2f
MD5 0a5158de13d050e0d23bb2175f40035b
BLAKE2b-256 2c64e8b0fdbfd03cbe50409ade485e422e218ee9f701532b78d81d24f277a890

See more details on using hashes here.

File details

Details for the file pacsys-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pacsys-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 292.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pacsys-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f72e939a0978dd7a377d262eab4c494e5d9f9bdfdd8a5000ecead4faeb62d93
MD5 a64bb65bf86a57b8d8711df0da1444b8
BLAKE2b-256 9e7d2f55d446586c19d8f73482cbcd4b46bd8b8a6165dcd40f4cea07a0486171

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