Python 3.x 在python中将json模式转换为avro模式

Python 3.x 在python中将json模式转换为avro模式,python-3.x,avro,jsonschema,Python 3.x,Avro,Jsonschema,我想使用python将json模式转换为avro模式,因为我正在用python Fastapi构建我的微服务 json模式 { "type":"object", "properties":{ "IsNonPO":{ "title":"IsNonPO", "type":[ &q

我想使用python将json模式转换为avro模式,因为我正在用python Fastapi构建我的微服务

json模式

{
   "type":"object",
   "properties":{
      "IsNonPO":{
         "title":"IsNonPO",
         "type":[
            "boolean",
            "null"
         ],
         "precision":null,
         "scale":null,
         "size":null,
         "allowedValues":null
      },
      "ApprovedState":{
         "title":"ApprovedState",
         "type":[
            "number",
            "null"
         ],
         "precision":null,
         "scale":null,
         "size":null,
         "allowedValues":[
            {
               "key":"8",
               "value":"Invalid"
            },
            {
               "key":"1",
               "value":"Composing"
            },
            {
               "key":"2",
               "value":"Submitted"
            },
            {
               "key":"4",
               "value":"Approved"
            },
            {
               "key":"16",
               "value":"Denied"
            }
         ]
      },
      "CreateDate":{
         "title":"CreateDate",
         "type":[
            "string",
            "null"
         ],
         "precision":null,
         "scale":null,
         "size":null,
         "allowedValues":null,
         "format":"date-time"
      },
      "RemitToAddress": {
            "type": ["object", "null"],
            "properties": {
                "State": {
                    "title": "RemitToAddress.State",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 50,
                    "allowedValues": null
                },
                "Phone": {
                    "title": "RemitToAddress.Phone",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 70,
                    "allowedValues": null
                },
                "Country": {
                    "type": ["object", "null"],
                    "properties": {
                        "UniqueName": {
                            "title": "RemitToAddress.Country.UniqueName",
                            "type": ["string", "null"],
                            "precision": null,
                            "scale": null,
                            "size": 50,
                            "allowedValues": null
                        }
                    }
                },
                "PostalCode": {
                    "title": "RemitToAddress.PostalCode",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 50,
                    "allowedValues": null
                },
                "City": {
                    "title": "RemitToAddress.City",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 50,
                    "allowedValues": null
                },
                "Fax": {
                    "title": "RemitToAddress.Fax",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 70,
                    "allowedValues": null
                },
                "UniqueName": {
                    "title": "RemitToAddress.UniqueName",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 50,
                    "allowedValues": null
                },
                "Lines": {
                    "title": "RemitToAddress.Lines",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 1024,
                    "allowedValues": null
                },
                "Name": {
                    "title": "RemitToAddress.Name",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 128,
                    "allowedValues": null
                }
            }
        }
    }
}
{
   "type":"record",
   "name":"invoice",
   "namespace":"com.xyz.com",
   "fields":[
      {
         "name":"IsNonPO",
         "type":[
            "null",
            "boolean"
         ]
      },
      {
         "name":"ApprovedState",
         "type":[
            "null",
            "long"
         ]
      },
      {
         "name":"CreateDate",
         "type":[
            "null",
            {
               "type":"string",
               "logicalType":"timestamp-micros"
            }
         ]
      },
      {
         "name":"RemitToAddress",
         "type":[
            {
               "type":"record",
               "name":"RemitToAddress",
               "namespace":"com.xyz.com.invoice",
               "fields":[
                  {
                     "name":"City",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"Country",
                     "type":[
                        {
                           "type":"record",
                           "name":"Country",
                           "namespace":"com.xyz.com.invoice.RemitToAddress",
                           "fields":[
                              {
                                 "name":"UniqueName",
                                 "type":[
                                    "null",
                                    "string"
                                 ]
                              }
                           ]
                        },
                        "null"
                     ]
                  },
                  {
                     "name":"Fax",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"Lines",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"Name",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"Phone",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"PostalCode",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"State",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"UniqueName",
                     "type":[
                        "null",
                        "string"
                     ]
                  }
               ]
            },
            "null"
         ]
      }
   ]
}
Avro模式

{
   "type":"object",
   "properties":{
      "IsNonPO":{
         "title":"IsNonPO",
         "type":[
            "boolean",
            "null"
         ],
         "precision":null,
         "scale":null,
         "size":null,
         "allowedValues":null
      },
      "ApprovedState":{
         "title":"ApprovedState",
         "type":[
            "number",
            "null"
         ],
         "precision":null,
         "scale":null,
         "size":null,
         "allowedValues":[
            {
               "key":"8",
               "value":"Invalid"
            },
            {
               "key":"1",
               "value":"Composing"
            },
            {
               "key":"2",
               "value":"Submitted"
            },
            {
               "key":"4",
               "value":"Approved"
            },
            {
               "key":"16",
               "value":"Denied"
            }
         ]
      },
      "CreateDate":{
         "title":"CreateDate",
         "type":[
            "string",
            "null"
         ],
         "precision":null,
         "scale":null,
         "size":null,
         "allowedValues":null,
         "format":"date-time"
      },
      "RemitToAddress": {
            "type": ["object", "null"],
            "properties": {
                "State": {
                    "title": "RemitToAddress.State",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 50,
                    "allowedValues": null
                },
                "Phone": {
                    "title": "RemitToAddress.Phone",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 70,
                    "allowedValues": null
                },
                "Country": {
                    "type": ["object", "null"],
                    "properties": {
                        "UniqueName": {
                            "title": "RemitToAddress.Country.UniqueName",
                            "type": ["string", "null"],
                            "precision": null,
                            "scale": null,
                            "size": 50,
                            "allowedValues": null
                        }
                    }
                },
                "PostalCode": {
                    "title": "RemitToAddress.PostalCode",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 50,
                    "allowedValues": null
                },
                "City": {
                    "title": "RemitToAddress.City",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 50,
                    "allowedValues": null
                },
                "Fax": {
                    "title": "RemitToAddress.Fax",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 70,
                    "allowedValues": null
                },
                "UniqueName": {
                    "title": "RemitToAddress.UniqueName",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 50,
                    "allowedValues": null
                },
                "Lines": {
                    "title": "RemitToAddress.Lines",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 1024,
                    "allowedValues": null
                },
                "Name": {
                    "title": "RemitToAddress.Name",
                    "type": ["string", "null"],
                    "precision": null,
                    "scale": null,
                    "size": 128,
                    "allowedValues": null
                }
            }
        }
    }
}
{
   "type":"record",
   "name":"invoice",
   "namespace":"com.xyz.com",
   "fields":[
      {
         "name":"IsNonPO",
         "type":[
            "null",
            "boolean"
         ]
      },
      {
         "name":"ApprovedState",
         "type":[
            "null",
            "long"
         ]
      },
      {
         "name":"CreateDate",
         "type":[
            "null",
            {
               "type":"string",
               "logicalType":"timestamp-micros"
            }
         ]
      },
      {
         "name":"RemitToAddress",
         "type":[
            {
               "type":"record",
               "name":"RemitToAddress",
               "namespace":"com.xyz.com.invoice",
               "fields":[
                  {
                     "name":"City",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"Country",
                     "type":[
                        {
                           "type":"record",
                           "name":"Country",
                           "namespace":"com.xyz.com.invoice.RemitToAddress",
                           "fields":[
                              {
                                 "name":"UniqueName",
                                 "type":[
                                    "null",
                                    "string"
                                 ]
                              }
                           ]
                        },
                        "null"
                     ]
                  },
                  {
                     "name":"Fax",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"Lines",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"Name",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"Phone",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"PostalCode",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"State",
                     "type":[
                        "null",
                        "string"
                     ]
                  },
                  {
                     "name":"UniqueName",
                     "type":[
                        "null",
                        "string"
                     ]
                  }
               ]
            },
            "null"
         ]
      }
   ]
}
我试图用python找到转换器,但找不到。我找到了一个,但它是用java实现的。请告诉我是否存在任何Python转换器,或者我是否编写了自己的库