p4p

raw JSON →
4.2.2 verified Sat May 09 auth: no python

Python interface to PVAccess (PV Access) protocol client for EPICS. Current version 4.2.2, supports Python >=2.7. Maintained by EPICS community, follow EPICS release cadence.

pip install p4p
error ImportError: cannot import name 'Context' from 'p4p'
cause Using old import path: `from p4p import Context`. Context moved to `p4p.client` in v4.
fix
Change to: from p4p.client import Context
error ModuleNotFoundError: No module named 'p4p.client.rpc'
cause The rpc module was deprecated and removed in p4p 4.2.
fix
Use from p4p.client.pva import Context and use .rpc() method on context instead of separate rpc module.
error TypeError: __init__() got an unexpected keyword argument 'provider'
cause In p4p <4.0, Context accepted `provider` as keyword; later versions use positional first argument.
fix
Use Context('pva') instead of Context(provider='pva').
error p4p.client.pva.ChannelTimeout: Channel timeout
cause PV name not found or network issues; default timeout is 5 seconds.
fix
Check PV name spelling, network connectivity, or increase timeout: ctx.get('pvname', timeout=10)
breaking p4p 4.0 removed support for Python 2.7. Users on older systems must pin to p4p<4.0.
fix Use Python 3.6+ or pin to p4p==3.x.
breaking Context usage changed: old import path `from p4p import Context` no longer works; use `from p4p.client import Context`.
fix Update imports to `from p4p.client import Context`.
deprecated The `rpc` module (p4p.client.rpc) is deprecated in favor of new `p4p.client.pva` for all operations. Expect removal in a future major release.
fix Migrate from `from p4p.client import rpc` to `from p4p.client.pva import Context`.
gotcha Many examples use `Context('pva', ...)` but the provider string is environment-specific. Default provider 'pva' works for most sites, but if server uses 'ca' or custom, must specify correctly.
fix Check site's PV Access provider setting (e.g., EPICS_PVA_PROVIDER). Use `Context('pva')` for native PVA, or `Context('ca')` for Channel Access relay.
gotcha Monitoring channels using `ctx.monitor()` returns an iterator that blocks indefinitely. For GUI or non-blocking applications, use `ch = ctx.monitor(...); ch.start()` with callbacks (see docs for `start` method).
fix Use callback-based monitoring: `ch = ctx.monitor(...); ch.start(lambda x: print(x))`

Create a PVA client context, fetch a value or monitor a PV.

import os
from p4p.client.pva import Context

with Context('pva') as ctx:
    value = ctx.get(os.environ.get('PV_NAME', 'blah:example'))
    print(value)

# Alternatively, using channel for monitoring:
with Context('pva') as ctx:
    ch = ctx.monitor(os.environ.get('PV_NAME', 'blah:example'))
    for update in ch:
        print(update)
        break  # just one sample