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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
%global _empty_manifest_terminate_build 0
Name: python-pydifact
Version: 0.1.6
Release: 1
Summary: A Python EDI file parser.
License: MIT
URL: https://github.com/nerdocs/pydifact
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/32/3e/283218a3c61fb41a1500111080de9bf31f299f8af1f18d4a39a65e787cde/pydifact-0.1.6.tar.gz
BuildArch: noarch
%description
# pydifact
A Python library to parse and serialize UN/EDIFACT interchanges.
## Preamble
This is a port of [metroplex-systems/edifact](https://github.com/metroplex-systems/edifact) to Python. Thanks here at the start to [Craig Duncan](https://github.com/duncan3dc) for this cool piece of software. Porting was like a breeze due to the high code quality there. All credits for the initial code here go to him, I just did the translation to Python(3), some "pythonifications" of the code and little improvements.
### Why another EDIFACT library?
Because I did not find a decent UN/EDIFACT library for Python, so I decided to port one of the available good PHP libraries to Python. Here is the result.
ATM this is a Work In Progress, the API is not stable yet.
Feel free to help.
## Install
As usual, use a virtualenv, and install via pip or pipenv:
```bash
pip install pydifact
```
However, it is not stable yet, so the pypi version, including documentation and code examples, could differ from the latest git code. If in doubt, use the git version:
```bash
git clone https://github.com/nerdocs/pydifact.git
cd pydifact
pip install -e .
```
## Usage
To read a full Interchange from a file or string, take the `Interchange` class and
iter over the messages and segments:
```python
from pydifact.segmentcollection import Interchange
interchange = Interchange.from_file("./tests/data/order.edi")
interchange = Interchange.from_str(
"UNA:+,? 'UNB+UNOC:1+1234+3333+200102:2212+42'UNH+42z42+PAORES:93:1:IA'UNT+2+42z42'UNZ+2+42'"
)
for message in interchange.get_messages():
for segment in message.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
You may also want to iterate directly on segments :
```python
from pydifact.segmentcollection import Interchange
interchange = Interchange.from_file("./tests/data/order.edi")
interchange = Interchange.from_str("UNA:+,? 'UNH+1+ORDERS:D:96A:UN:EAN008'")
for segment in interchange.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
Or you can create an EDI interchange on the fly:
```python
from pydifact.segmentcollection import Interchange
from pydifact.segments import Segment
interchange = Interchange()
interchange.add_segment(Segment('QTY', ['12', '3']))
print(interchange.serialize())
```
You may also want to parse a « raw » segment bunch which is not an interchange :
```
from pydifact.segmentcollection import RawSegmentCollection
collection = RawSegmentCollection.from_str("UNH+1+ORDERS:D:96A:UN:EAN008'")
for segment in collection.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
## Limitations
- No support of optional functional groups (`UNG`→`UNE`),
## Alternatives
In python ecosystem:
- [python-edifact](https://github.com/FriedrichK/python-edifact) - simpler, IMHO less cleaner code, less flexible. may be faster though (not tested). Seems unmaintained.
- [bots](https://github.com/bots-edi/bots) - huge, with webinterface (bots-monitor), webserver, bots-engine.
- [edicat](https://github.com/notpeter/edicat) - simple, only for separating lines/segments for CLI-piping.
## Development
To develop pydifact, install the dev requirements with `pipenv install --dev`. This installs all the python packages needed for development and testing.
Format all python files using [black](https://black.readthedocs.io).
Happy coding, PR are more than welcome to make this library better, or to add a feature that matches your needs. Nevertheless, don't forget adding tests for every aspect you add in code.
### Testing
pydifact uses [pytest](http://pytest.org) for testing.
Just exec `pytest` within the project folder to execute the unit tests.
There is one test to check the performance of parsing huge files, named `test_huge_message` - you can skip that test by calling
```bash
pytest --ignore tests/test_huge_message.py
```
This is recommended for fast testing.
## License
This library is licensed under the
*MIT* license, see the
[LICENSE file](LICENSE).
%package -n python3-pydifact
Summary: A Python EDI file parser.
Provides: python-pydifact
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-pydifact
# pydifact
A Python library to parse and serialize UN/EDIFACT interchanges.
## Preamble
This is a port of [metroplex-systems/edifact](https://github.com/metroplex-systems/edifact) to Python. Thanks here at the start to [Craig Duncan](https://github.com/duncan3dc) for this cool piece of software. Porting was like a breeze due to the high code quality there. All credits for the initial code here go to him, I just did the translation to Python(3), some "pythonifications" of the code and little improvements.
### Why another EDIFACT library?
Because I did not find a decent UN/EDIFACT library for Python, so I decided to port one of the available good PHP libraries to Python. Here is the result.
ATM this is a Work In Progress, the API is not stable yet.
Feel free to help.
## Install
As usual, use a virtualenv, and install via pip or pipenv:
```bash
pip install pydifact
```
However, it is not stable yet, so the pypi version, including documentation and code examples, could differ from the latest git code. If in doubt, use the git version:
```bash
git clone https://github.com/nerdocs/pydifact.git
cd pydifact
pip install -e .
```
## Usage
To read a full Interchange from a file or string, take the `Interchange` class and
iter over the messages and segments:
```python
from pydifact.segmentcollection import Interchange
interchange = Interchange.from_file("./tests/data/order.edi")
interchange = Interchange.from_str(
"UNA:+,? 'UNB+UNOC:1+1234+3333+200102:2212+42'UNH+42z42+PAORES:93:1:IA'UNT+2+42z42'UNZ+2+42'"
)
for message in interchange.get_messages():
for segment in message.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
You may also want to iterate directly on segments :
```python
from pydifact.segmentcollection import Interchange
interchange = Interchange.from_file("./tests/data/order.edi")
interchange = Interchange.from_str("UNA:+,? 'UNH+1+ORDERS:D:96A:UN:EAN008'")
for segment in interchange.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
Or you can create an EDI interchange on the fly:
```python
from pydifact.segmentcollection import Interchange
from pydifact.segments import Segment
interchange = Interchange()
interchange.add_segment(Segment('QTY', ['12', '3']))
print(interchange.serialize())
```
You may also want to parse a « raw » segment bunch which is not an interchange :
```
from pydifact.segmentcollection import RawSegmentCollection
collection = RawSegmentCollection.from_str("UNH+1+ORDERS:D:96A:UN:EAN008'")
for segment in collection.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
## Limitations
- No support of optional functional groups (`UNG`→`UNE`),
## Alternatives
In python ecosystem:
- [python-edifact](https://github.com/FriedrichK/python-edifact) - simpler, IMHO less cleaner code, less flexible. may be faster though (not tested). Seems unmaintained.
- [bots](https://github.com/bots-edi/bots) - huge, with webinterface (bots-monitor), webserver, bots-engine.
- [edicat](https://github.com/notpeter/edicat) - simple, only for separating lines/segments for CLI-piping.
## Development
To develop pydifact, install the dev requirements with `pipenv install --dev`. This installs all the python packages needed for development and testing.
Format all python files using [black](https://black.readthedocs.io).
Happy coding, PR are more than welcome to make this library better, or to add a feature that matches your needs. Nevertheless, don't forget adding tests for every aspect you add in code.
### Testing
pydifact uses [pytest](http://pytest.org) for testing.
Just exec `pytest` within the project folder to execute the unit tests.
There is one test to check the performance of parsing huge files, named `test_huge_message` - you can skip that test by calling
```bash
pytest --ignore tests/test_huge_message.py
```
This is recommended for fast testing.
## License
This library is licensed under the
*MIT* license, see the
[LICENSE file](LICENSE).
%package help
Summary: Development documents and examples for pydifact
Provides: python3-pydifact-doc
%description help
# pydifact
A Python library to parse and serialize UN/EDIFACT interchanges.
## Preamble
This is a port of [metroplex-systems/edifact](https://github.com/metroplex-systems/edifact) to Python. Thanks here at the start to [Craig Duncan](https://github.com/duncan3dc) for this cool piece of software. Porting was like a breeze due to the high code quality there. All credits for the initial code here go to him, I just did the translation to Python(3), some "pythonifications" of the code and little improvements.
### Why another EDIFACT library?
Because I did not find a decent UN/EDIFACT library for Python, so I decided to port one of the available good PHP libraries to Python. Here is the result.
ATM this is a Work In Progress, the API is not stable yet.
Feel free to help.
## Install
As usual, use a virtualenv, and install via pip or pipenv:
```bash
pip install pydifact
```
However, it is not stable yet, so the pypi version, including documentation and code examples, could differ from the latest git code. If in doubt, use the git version:
```bash
git clone https://github.com/nerdocs/pydifact.git
cd pydifact
pip install -e .
```
## Usage
To read a full Interchange from a file or string, take the `Interchange` class and
iter over the messages and segments:
```python
from pydifact.segmentcollection import Interchange
interchange = Interchange.from_file("./tests/data/order.edi")
interchange = Interchange.from_str(
"UNA:+,? 'UNB+UNOC:1+1234+3333+200102:2212+42'UNH+42z42+PAORES:93:1:IA'UNT+2+42z42'UNZ+2+42'"
)
for message in interchange.get_messages():
for segment in message.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
You may also want to iterate directly on segments :
```python
from pydifact.segmentcollection import Interchange
interchange = Interchange.from_file("./tests/data/order.edi")
interchange = Interchange.from_str("UNA:+,? 'UNH+1+ORDERS:D:96A:UN:EAN008'")
for segment in interchange.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
Or you can create an EDI interchange on the fly:
```python
from pydifact.segmentcollection import Interchange
from pydifact.segments import Segment
interchange = Interchange()
interchange.add_segment(Segment('QTY', ['12', '3']))
print(interchange.serialize())
```
You may also want to parse a « raw » segment bunch which is not an interchange :
```
from pydifact.segmentcollection import RawSegmentCollection
collection = RawSegmentCollection.from_str("UNH+1+ORDERS:D:96A:UN:EAN008'")
for segment in collection.segments:
print('Segment tag: {}, content: {}'.format(
segment.tag, segment.elements))
```
## Limitations
- No support of optional functional groups (`UNG`→`UNE`),
## Alternatives
In python ecosystem:
- [python-edifact](https://github.com/FriedrichK/python-edifact) - simpler, IMHO less cleaner code, less flexible. may be faster though (not tested). Seems unmaintained.
- [bots](https://github.com/bots-edi/bots) - huge, with webinterface (bots-monitor), webserver, bots-engine.
- [edicat](https://github.com/notpeter/edicat) - simple, only for separating lines/segments for CLI-piping.
## Development
To develop pydifact, install the dev requirements with `pipenv install --dev`. This installs all the python packages needed for development and testing.
Format all python files using [black](https://black.readthedocs.io).
Happy coding, PR are more than welcome to make this library better, or to add a feature that matches your needs. Nevertheless, don't forget adding tests for every aspect you add in code.
### Testing
pydifact uses [pytest](http://pytest.org) for testing.
Just exec `pytest` within the project folder to execute the unit tests.
There is one test to check the performance of parsing huge files, named `test_huge_message` - you can skip that test by calling
```bash
pytest --ignore tests/test_huge_message.py
```
This is recommended for fast testing.
## License
This library is licensed under the
*MIT* license, see the
[LICENSE file](LICENSE).
%prep
%autosetup -n pydifact-0.1.6
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-pydifact -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 0.1.6-1
- Package Spec generated
|