Skip to main content

Generate test data from JSON schemata with Hypothesis

Project description

hypothesis-jsonschema

A Hypothesis strategy for generating data that matches some JSON schema. It is currently in early alpha, but you can use it if you want.

The public API consists of a just two functions:

hypothesis_jsonschema.from_schema

Takes a JSON schema and return a strategy for allowed JSON objects.

This strategy supports almost all of the schema elements described in the draft RFC as of November 2018 (draft 7), with the following exceptions:

For arrays, the "contains" keyword is not supported. For objects, the "dependencies" keyword is not supported. Subschemata are not supported, i.e. the "if", "then", and "else" keywords, and the "allOf, "anyOf", "oneOf", and "not" keywords. For strings, the "format" keyword is not supported. Schema reuse with "definitions" is not supported.

The following features are deemed out of scope - pull requests would be accepted (if maintainable) but issues would not:

  • string-encoding of non-JSON data
  • schema annotations, i.e. "title", "description", "default", "readOnly", "writeOnly", and "examples"
  • JSON pointers

hypothesis_jsonschema.json_schemata

A Hypothesis strategy for arbitrary JSON schemata.

This strategy may generate anything that can be handled by from_schema, and is used to provide full branch coverage when testing this package.

Supported versions

hypothesis-jsonschema does not support Python 2, because it's close to end of life and Python 3.6+ is a much nicer language. Contact me if you would like this changed and are willing to either pay for or do the work to support Python 2.

In general, 0.x versions will require very recent versions of all dependencies because I don't want to deal with compatibility workarounds.

hypothesis-jsonschema may make backwards-incompatible changes at any time before version 1.x - that's what semver means! - but I've kept the API surface small enough that this should be avoidable. The main source of breaks will be if or when schema that never really worked turn into explicit errors instead of generating values that don't quite match.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hypothesis-jsonschema-0.3.0.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file hypothesis-jsonschema-0.3.0.tar.gz.

File metadata

  • Download URL: hypothesis-jsonschema-0.3.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for hypothesis-jsonschema-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0d398698003077e129a98591f500d2a905f5f9828c47d5f1bc4138d5a5546a6f
MD5 e6800de1058a6fcafee51af380d673f2
BLAKE2b-256 35745b30d47ef2089f0bb7bd391d0e95403edfb76d5fed6719c3d0be6904e200

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page