File: README.md

package info (click to toggle)
python-varlink 31.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 372 kB
  • sloc: python: 2,462; sh: 177; makefile: 31
file content (218 lines) | stat: -rw-r--r-- 5,265 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
[![Varlink Certified](https://img.shields.io/badge/varlink-certified-green.svg)](https://www.varlink.org/Language-Bindings)
[![Build Status](https://travis-ci.org/varlink/python.svg?branch=master)](https://travis-ci.org/varlink/python)
[![Coverage Status](https://coveralls.io/repos/github/varlink/python/badge.svg?branch=master)](https://coveralls.io/github/varlink/python?branch=master)
[![PyPI](https://img.shields.io/pypi/v/varlink.svg)](https://pypi.org/project/varlink/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/varlink.svg)](https://pypi.org/project/varlink/)
[![PyPI - Status](https://img.shields.io/pypi/status/varlink.svg)](https://pypi.org/project/varlink/)

# python-varlink

A [varlink](http://varlink.org) implementation for Python.

* [GIT Repository](https://github.com/varlink/python)
* [API documentation](https://varlink.github.io/python/)

## python varlink installation

From pypi:
```bash
$ pip3 install --user varlink
```

With Fedora 28/rawhide:
```bash
$ sudo dnf install python3-varlink
```

## Examples

See the [tests](https://github.com/varlink/python-varlink/tree/master/varlink/tests) directory.

```bash
$ python3 -m varlink.tests.test_orgexamplemore --varlink="unix:/tmp/test" &
[1] 6434
$ python -m varlink.cli help unix:/tmp/test/org.example.more
# Example Varlink service
interface org.example.more

# Enum, returning either start, progress or end
# progress: [0-100]
type State (
  start: ?bool,
  progress: ?int,
  end: ?bool
)

# Returns the same string
method Ping(ping: string) -> (pong: string)

# Dummy progress method
# n: number of progress steps
method TestMore(n: int) -> (state: State)

# Stop serving
method StopServing() -> ()

# Something failed in TestMore
error TestMoreError (reason: string)

$ python -m varlink.cli call unix:/tmp/test/org.example.more.Ping '{ "ping": "Ping"}'
{
  "pong": "Ping"
}
 

$ fg
python3 -m varlink.tests.test_orgexamplemore --varlink="unix:/tmp/test"
^C
```

```bash
$ python3 -m varlink.tests.test_orgexamplemore --client -A 'python3 -m varlink.tests.test_orgexamplemore --varlink=$VARLINK_ADDRESS'
Connecting to unix:/tmp/tmppxrbqk9p/4927

Listening on /tmp/tmppxrbqk9p/4927
--- Start ---
Progress: 0
Progress: 10
Progress: 20
Progress: 30
Progress: 40
Progress: 50
Progress: 60
Ping:  Test
Progress: 70
Ping:  Test
Progress: 80
Ping:  Test
Progress: 90
Ping:  Test
Progress: 100
Ping:  Test
--- End ---
```

```bash
$ PYTHONPATH=$(pwd) python3 ./varlink/tests/test_orgexamplemore.py
Connecting to unix:/tmp/tmp7n6zc67d/5257

Listening on /tmp/tmp7n6zc67d/5257
--- Start ---
Progress: 0
Progress: 10
Progress: 20
Progress: 30
Progress: 40
Progress: 50
Progress: 60
Ping:  Test
Progress: 70
Ping:  Test
Progress: 80
Ping:  Test
Progress: 90
Ping:  Test
Progress: 100
Ping:  Test
--- End ---
```

```bash
$ python3 -m varlink.tests.test_orgexamplemore --varlink="unix:/tmp/test" &
Listening on /tmp/test
[1] 6434
python3 -m varlink.tests.test_orgexamplemore --client --varlink="unix:/tmp/test"
Connecting to unix:/tmp/test

Ping:  Test
--- Start ---
Progress: 0
Progress: 10
Progress: 20
Progress: 30
Progress: 40
Progress: 50
Progress: 60
Ping:  Test
Progress: 70
Ping:  Test
Progress: 80
Ping:  Test
Progress: 90
Ping:  Test
Progress: 100
Ping:  Test
--- End ---

$ python3 -m varlink.cli call --more unix:/tmp/test/org.example.more.TestMore '{ "n": 10 }'
{'state': {'start': True}}
{'state': {'progress': 0}}
{'state': {'progress': 10}}
{'state': {'progress': 20}}
{'state': {'progress': 30}}
{'state': {'progress': 40}}
{'state': {'progress': 50}}
{'state': {'progress': 60}}
{'state': {'progress': 70}}
{'state': {'progress': 80}}
{'state': {'progress': 90}}
{'state': {'progress': 100}}
{'state': {'end': True}}

$ fg
python3 -m varlink.tests.test_orgexamplemore --varlink="unix:/tmp/test"
^C
```

You can also start the clients and server with URLs following the [varlink URL standard](https://varlink.org/#address) with `unix:` and `tcp:`.
E.g.
- unix:@anonuds
- unix:/run/myserver/socketfile
- tcp:127.0.0.1:12345
- tcp:[::1]:12345


### Activation Mode

Activation mode starts the service to connect to and passes the socket via socket activation.
The ```VARLINK_ADDRESS``` environment variable contains the varlink address URI.

```bash
$ python3 -m varlink.cli --activate 'python3 -m varlink.tests.test_orgexamplemore --varlink=$VARLINK_ADDRESS' call org.example.more.Ping '{ "ping": "Ping"}'
Listening on @00352
{'pong': 'Ping'}
```


### Bridge Mode

Bridge mode allows to tunnel to a remote point via stdin/stdout and call a method.
Running ```varlink bridge``` allows to connect stdio to the host services via ```org.varlink.resolver``` interface resolving.

```bash
# python3 -m varlink.cli -b "ssh host.example.org varlink bridge" call com.redhat.machine.GetInfo '{}'
{
  "hostname": "host.example.org",
  "system": {
    "id": "fedora",
    "kernel_version": "4.18.0-0.rc5.git1.2.fc29.x86_64",
    "name": "Fedora",
    "version": "29"
  },
  "virtualization": {
    "name": "none"
  }
}
```

### Varlink Certification Server

```
$ python3 -m varlink.tests.test_certification --varlink=tcp:127.0.0.1:12345
```

### Varlink Certification Client

```
$ python3 -m varlink.tests.test_certification --varlink=tcp:127.0.0.1:12345 --client
```