What happened in my case was that... 1) I need faster JSON schema validation 2) Let's check out Fast JSON Schema 3) Huh! How about that! You create the instance once and reuse it. Why don't I just do that with the existing stack? 4) Reusing existing stack but doing the create-instance-once pattern. 5) Totally good enough for now.
I hope my blog post shines some light - plus your comment here - about the fact that there is an alternative to regular python-jsonschema that is production grade and distinctly faster.
Hi. Author of the Fast JSON Schema here. :-)
I wrote about details of the project here: https://blog.horejsek.com/fastjsonschema/ It's ready for production code and offers full support of JSON Schema Draft 04, 06 and 07.
The reason why f4 is slow is that it creates Python code on the fly in every cycle. Using validate directly is really only when you are lazy and it's one time usage. To have high performance you should always use compile.
BTW you can gain little bit also by generating Python code to the file and import that instead. Maybe you could try to do f6. It should be even slightly better. :-) You can generate validation module for your schema with following command: echo "{'type': 'string'}" | python3 -m fastjsonschema > your_file.py (or use fastjsonschema.compile_to_code on your own: https://horejsek.github.io/python-fastjsonschema/#fastjsonschema.compile_to_code)
Comment
Thanks for sharing!
What happened in my case was that...
1) I need faster JSON schema validation
2) Let's check out Fast JSON Schema
3) Huh! How about that! You create the instance once and reuse it. Why don't I just do that with the existing stack?
4) Reusing existing stack but doing the create-instance-once pattern.
5) Totally good enough for now.
I hope my blog post shines some light - plus your comment here - about the fact that there is an alternative to regular python-jsonschema that is production grade and distinctly faster.
Parent comment
Hi. Author of the Fast JSON Schema here. :-) I wrote about details of the project here: https://blog.horejsek.com/fastjsonschema/ It's ready for production code and offers full support of JSON Schema Draft 04, 06 and 07. The reason why f4 is slow is that it creates Python code on the fly in every cycle. Using validate directly is really only when you are lazy and it's one time usage. To have high performance you should always use compile. BTW you can gain little bit also by generating Python code to the file and import that instead. Maybe you could try to do f6. It should be even slightly better. :-) You can generate validation module for your schema with following command: echo "{'type': 'string'}" | python3 -m fastjsonschema > your_file.py (or use fastjsonschema.compile_to_code on your own: https://horejsek.github.io/python-fastjsonschema/#fastjsonschema.compile_to_code)