0

I have a working AVRO converter that will output JSON formatted schema & records files and a CSV records file. To generate the JSON schema & recodes files I'm calling the following fastavro shell commands.

Schema:

subprocess.run("fastavro --schema -p" + avro_file + ">" + schout_file, shell=True, check=True)

Records:

subprocess.run("fastavro -p" + avro_file + ">" + rcdout_file, shell=True, check=True)

I really don't like calling a shell command from within my Python code, but this was the only way I have gotten this to work. Can someone show me how to replicate these fastavro commands only in Python-3. (I've looked everywhere in the docs and other sites but don't see the functionality of these commands written out as only Python code)

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Tarlak333
  • 1
  • 1
  • `>` is shell syntax, not part of the command. Does this answer your question? [How to redirect output with subprocess in Python?](/q/4965159/4518341) That said, I have no experience with `fastavro`, so I don't know if it could maybe have an "output file" argument that would be even easier. – wjandrea Aug 29 '23 at 18:20
  • 1
    @wjandrea I *think* the question is about how to use fastavro *as a library, instead of* using `subprocess` entirely. But as such - "how do I make basic use of X library?" is too broad; it's best answered by reading the [documentation](https://fastavro.readthedocs.io/en/latest/). – Karl Knechtel Aug 29 '23 at 18:23

0 Answers0