Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/fastavro/json_read.py: 83%

6 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 06:10 +0000

1from typing import IO 

2 

3from ._read_py import reader 

4from .io.json_decoder import AvroJSONDecoder 

5from .types import Schema 

6 

7 

8def json_reader(fo: IO, schema: Schema, *, decoder=AvroJSONDecoder) -> reader: 

9 """Iterator over records in an avro json file. 

10 

11 Parameters 

12 ---------- 

13 fo 

14 File-like object to read from 

15 schema 

16 Reader schema 

17 decoder 

18 By default the standard AvroJSONDecoder will be used, but a custom one 

19 could be passed here 

20 

21 

22 Example:: 

23 

24 from fastavro import json_reader 

25 

26 schema = { 

27 'doc': 'A weather reading.', 

28 'name': 'Weather', 

29 'namespace': 'test', 

30 'type': 'record', 

31 'fields': [ 

32 {'name': 'station', 'type': 'string'}, 

33 {'name': 'time', 'type': 'long'}, 

34 {'name': 'temp', 'type': 'int'}, 

35 ] 

36 } 

37 

38 with open('some-file', 'r') as fo: 

39 avro_reader = json_reader(fo, schema) 

40 for record in avro_reader: 

41 print(record) 

42 """ 

43 return reader(decoder(fo), schema)