Skip to main content

Model Definition Language for Pyjo

Project description

# pyjo-mdl
Model definition language for Pyjo


This package will allow you to dynamically create pyjo models with a
domain specific language created ad-hoc.

# Model definition language

We can define the structure of the model with a json format.
Heres a basic example:

```
{
"url": {
"type": "url",
"required": false
},
"name": {
"type": "string"
},
"rounds": {
"type": "array",
"element": {
"type": "embedded",
"model": {
"foo": {
"type": "string"
},
"bar": {
"type": "integer",
"min_value": 100
}
}
}
}
}
```

This allows to define models as a set of properties with some type
and validation.

As you can see, there are many possible properties in this DSL.
We want to keep it as simple as possible to start with,
so heres a very basic list of stuff that we plan to add
from the beginning.
More stuff will come in the future as needs arise.

# Available properties and options

### Some generally available options:
- `required`: true if the property must be always filled when providing content. Defaults to true
- `type`: type of the property, see below for a proposal of the initial set of properties available


### string
Basic string field, may contain any set of UTF-8 characters.
Extra options:

- `validation`: a regular expression the string must satisfy
- `min_length`: Min number of chars in the string, defaults to 0
- `max_length`: Max number of chars in the string, defaults to infinite!
- `values`: array of all and only possible values for this field

Example:

```
{
"tag_version": {
"type": "string",
"validation": "^.*-[0-9]\.[0-9]\.[0-9]build[0-9]+$"
"max_length": 256
}
}
```

Example (enum):

```
{
"meal_category": {
"type": "string",
"values": [
"smoothie",
"main dish",
"dessert",
]
}
}
```


### integer
Integer number. Extras:

- `min_value`: min value allowed
- `max_value`: max value allowed

```
{
"calories": {
"type": "integer",
"min_value": 0
}
}
```


### float
Floating point number. Extras:

- `min_value`: min value allowed
- `max_value`: max value allowed

```
{
"price": {
"type": "float",
"min_value": 0,
"max_value": 99.99
}
}
```


### boolean
Flag, true or false. Cant be easier than this.

```
{
"hidden": {
"type": "boolean"
}
}
```

Booleans will automatically consider values in
`yes, true, t, y, 1` to be truthy (ignoring case),
values in `no, false, f, n, 0` to be falsy. Other string values will
raise an exception.

### url:
URLs are validated with the following regex:
`http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+`

```
{
"cover_image": {
"type": "url"
}
}
```

### embedded
Represents an embedded model that may have no meaning outside of the
main model. Its useful to represent some nested data structure.
May contain all the properties of a full model. Must contain:

- `model`: the model structure being embedded

Example

```
{
"pet": {
"type": "embedded",
"model": {
"name": {
"type": "string",
},
"age": {
"type": "integer",
"min_value": 0
}
}
}
}
```

### array
Represents a list of fields of any kind, including embedded. Extras:

- `element`: defines the kind of element in this array property. It may be of any kind, including embedded

Examples (primitive content):

```
{
"lucky_numbers": {
"type": "array",
"element": {
"type": "integer"
}
}
}
```

Example 2 (embedded complex models):

```
{
"pets": {
"type": "array",
"element": {
"type": "embedded",
"model": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"min_value": 0
}
}
}
}
}
```


Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyjo_mdl-0.1.4-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pyjo_mdl-0.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: pyjo_mdl-0.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15

File hashes

Hashes for pyjo_mdl-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bf13560a0384630add7d5795bd12581b90a1da9045a391b9c16f086b74c4f748
MD5 7a75161fdb587f35192923519fb2a64d
BLAKE2b-256 e9a45ec0543d81f548dc9f4e6be8fb70204cb9769dae8374c94680d21121d69c

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