title: How can I parse JSON into a binary Avro file using the Python Avro api?
body: <p>I am able to use the avro-tools-1.7.7.jar to take json data and avro schema and output a binary Avro file as shown here <a href="https://github.com/miguno/avro-cli-examples#json-to-avro" rel="nofollow noreferrer">https://github.com/miguno/avro-cli-examples#json-to-avro</a>. However, I want to be able to do this programmatically using the Avro python api: <a href="https://avro.apache.org/docs/1.7.7/gettingstartedpython.html" rel="nofollow noreferrer">https://avro.apache.org/docs/1.7.7/gettingstartedpython.html</a>. </p>
  
  <p>In their example they show how you can write a record at a time into a binary avro file.</p>
  
  <pre><code>    import avro.schema
      from avro.datafile import DataFileReader, DataFileWriter
      from avro.io import DatumReader, DatumWriter
  
      schema = avro.schema.parse(open("user.avsc").read())
  
      writer = DataFileWriter(open("users.avro", "w"), DatumWriter(), schema)
      writer.append({"name": "Alyssa", "favorite_number": 256})
      writer.append({"name": "Ben", "favorite_number": 7, "favorite_color": "red"})
      writer.close()
  </code></pre>
  
  <p>My use case is writing all of the records at once like the avro-tools jar does from a json file, just in python code. I do not want to shell out and execute the jar. This will be deployed to Google App Engine if that matters.</p>