asyncvarlink
This is a pure Python implementation of the varlink IPC
protocol based on asyncio. The main differences to he reference
implementation are:
- Usage of
asyncioinstead of synchronous threading - Where the reference implementation parses a varlink interface description as a source of truth, this implementation derives a varlink interface description from a typed Python class to describe an interface.
- Even though the varlink faq explicitly renders
passing file descriptors out of scope,
systemduses it and it is an important feature also implemented here.
Client usage
The VarlinkServiceInterface class represents the org.varlink.service
introspection interface. We can use it to introspect systemd-hostnamed.
import asyncio
from asyncvarlink import VarlinkClientProtocol, connect_unix_varlink
from asyncvarlink.serviceinterface import VarlinkServiceInterface
async def main() -> None:
t, p = await connect_unix_varlink(
VarlinkClientProtocol, "/run/systemd/io.systemd.Hostname"
)
i = p.make_proxy(VarlinkServiceInterface)
print(await i.GetInfo())
t.close()
asyncio.run(main())
Server usage
Here is an example for defining an interface. If it is to be used by a server, the methods need to be implemented of course, but on the client side, typed stubs will do.
import asyncio
import collections.abc
import enum
from asyncvarlink import VarlinkInterface, varlinkmethod
class Direction(enum.Enum):
left = "left"
right = "right"
class DemoInterface(VarlinkInterface, name="com.example.demo"):
@varlinkmethod(return_parameter="direction")
def Reverse(self, *, value: Direction) -> Direction:
return Direction.left if value == Direction.right else Direction.right
@varlinkmethod(return_parameter="value")
def Range(self, *, count: int) -> collections.abc.Iterator[int]:
return iter(range(count))
@varlinkmethod
async def Sleep(self, *, delay: float) -> None:
await asyncio.sleep(delay)
Setting up a service is now a matter of plugging things together.
import asyncio
import sys
from asyncvarlink import VarlinkInterfaceRegistry, VarlinkTransport
from asyncvarlink.serviceinterface import VarlinkServiceInterface
registry = VarlinkInterfaceRegistry()
registry.register_interface(
VarlinkServiceInterface(
"ExampleVendor",
"DemonstrationProduct",
"1.0",
"https://github.com/helmutg/asyncvarlink",
registry,
),
)
registry.register_interface(DemoInterface())
VarlinkTransport(
asyncio.get_event_loop(),
sys.stdin.fileno(),
sys.stdout.fileno(),
registry.protocol_factory(),
)
When communicating via stdio, varlinkctl from systemd may be used to
interact with a service. Registering a VarlinkServiceInterface implementing
the org.varlink.service introspection interface is optional.
Documentation
The source for sphinxdoc documentation resides below docs/.
A rendered version is published on github pages.
Collaboration
The primary means of collaborating on this project is
github. If you prefer not to use a
centralized forge, sending inquiries and patches to
Helmut is also welcome. Please
refer to HACKING.md for more information on development processes.
License
LGPL-2.0-or-later
Metadata
Release files for asyncvarlink 0.3.3
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 | Actions |
|---|---|---|---|---|
| asyncvarlink-0.3.3.tar.gz | 61.6 kB | Without provenance | Details for asyncvarlink-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asyncvarlink-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for asyncvarlink-0.3.3-py3-none-any.whl |
Total release size: 111.6 kB
Release files / asyncvarlink-0.3.3.tar.gz
| Download URL | asyncvarlink-0.3.3.tar.gz |
|---|---|
| Size | 61.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0270e352d5c8d5348b90f547a4215bfb37a6b829b84341822f80273e830dadd4
|
|
BLAKE2b-256 checksum How to use checksums |
5988afd4b0f85e966ffbedbd46f6e362fe0227d8e0e94763992b06fbef0b014d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.34.2
|
Release files / asyncvarlink-0.3.3-py3-none-any.whl
| Download URL | asyncvarlink-0.3.3-py3-none-any.whl |
|---|---|
| Size | 50.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f87b0a711ea3bfe6b4b2698450dcfbfdcfc38349532b604d0ce17d3f00ac395e
|
|
BLAKE2b-256 checksum How to use checksums |
436e0124a54b43bac718fa7fbe1c1f27910ac67a6dd4d232431eef60fafb4c7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.34.2
|
Security for asyncvarlink 0.3.3
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.