Provides random samples of given json schema
Project description
freddy
Provides randomized json data (samples) that complies with a given json schema.
Usage
from pprint import pprint
import jsonschema
import freddy
family_schema = {
"type": "array",
"items": {
"properties": {
"member": {"$ref": "#/definitions/person"},
"role": {"$ref": "#/definitions/role"},
},
"type": "object",
},
"maxItems": 5,
"minItems": 1,
"definitions": {
"person": {
"properties": {
"age": {"type": "integer"},
"name": {"type": "string"},
"pets": {
"items": {"$ref": "#/definitions/pet"},
"maxItems": 2,
"type": "array",
},
},
"type": "object",
},
"pet": {
"properties": {
"kind": {"enum": ["dog", "cat"], "type": "string"},
"name": {"type": "string"},
},
"type": "object",
},
"role": {
"enum": [
"father",
"mather",
"son",
"daughter",
"aunt",
"grandma",
"grandpa",
],
"type": "string",
},
}
}
# Get 10 random samples
for i in range(10):
sample_family = freddy.jsonschema(family_schema)
# Validate against schema
jsonschema.validate(sample_family, family_schema)
pprint(sample_family)
[
{"member": {"age": 77, "name": "k", "pets": []}, "role": "grandma"},
{"member": {"age": 64, "name": "naifvxf", "pets": []}, "role": "grandpa"},
{
"member": {
"age": 23,
"name": "itruydotrj",
"pets": [{"kind": "cat", "name": "o"}, {"kind": "cat", "name": "uonmvfgd"}],
},
"role": "son",
},
]
Install
pip install freddy
Development
# Clone the repo
git@github.com:lferran/freddy.git
cd freddy
make develop
# Run tests
make tests
JSON Schema support
Conforms to JSON Schema Draft 7. The following features are supported:
-
boolean type
-
null type
-
string type
-
number type
-
integer type
-
array type
-
object type
-
definitions/references
-
Boolean type
-
consts
-
exclusiveMinimum
andexclusiveMaximum
in integers and numbers. -
number
multipleOf
keyword -
required
keyword -
additionalProperties
-
string
pattern
regex keyword -
string built-in formats
-
be able to provide custom basic type factories
-
multiple types:
{"type": ["string", "array"]}
-
look into
allOf
: generate multiple objects + merge
Does not support:
- ID referencing
allOf
andnot
keywords- conditional keywords
if
,then
andelse
patternProperties
on objects- property and schema
dependencies
on objects.
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
File details
Details for the file freddy-2.0.1.tar.gz
.
File metadata
- Download URL: freddy-2.0.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0059463921ee0c9f1ff74eea2d2a587c7974273ad75256ac1415257ebba4c9da |
|
MD5 | 391f76829d739c9a12bb4b9e90567a94 |
|
BLAKE2b-256 | 7a632db830de965c2b2e4d04fc9ad252b543948c986946616d7382f34e5de7f6 |