Comments (7)
I'm not sure about this one. You can already read unstructured, schemaless data using strictyaml and you can also create partial schemas. You can ratchet up the strictness incrementally rather than generating a great big schema (which will likely change).
I'm also pretty averse to writing code generation tools (I've seen them go wrong too many times).
I'm intending on allowing the use of kwalify schemas at some point, but since these don't work for more complex schemas, it would be alongside the existing pythonic schema language.
from strictyaml.
Correct me if I am mistaken, but I see it as very straightforward recursive constructor for validators with uniform direct correspondence to existing python validator classes and their parameters.
This would be trivial to implement but would be a pain to keep up-to-date if not being part of the strictyaml
itself. I suspect that creative (isn't it always?) use of decorators on Validator classes could make this simple and elegant.
I don't quite get your remark on "code generation tools".
from strictyaml.
Are you suggesting something like this::
x:
a: 1
b: 2
strictyaml.generate_schema(yaml_string) == """Map({"x": Map({"a": Int(), "b": Int()})})"""
from strictyaml.
No. Rather:
schema = Map({
"u": Seq(Bool),
"x": Int(),
"y": Enum(["a", "b", "c"]),
"z": MapPattern(Int(), Str())
})
data = strictyaml.load(yaml_str, schema)
could be done as:
yaml_schema_str="""
type: Map
validator:
- u:
type: Seq
validator:
type: Bool
- x:
type: Int
- y:
type: Enum
restricted_to:
- a
- b
- c
- z:
type: MapPattern
key_validator:
type: Int
value_validator:
type: Str
"""
yaml_schema_data = strictyaml.load(yaml_schema_str)
schema = strictyaml.construct_schema_from_data(yaml_schema_data)
data = strictyaml.load(yaml_str, schema)
The values in "type" can be any of the leaf Validator classes (I am not sure if all classes in the validators
module are meant to be usable by the user, or rather some are meant as base classes only). The rest of the keys should correspond to constructor arguments.
Just as I said earlier, I believe that something like that can be elegantly implementing by some decorators decorating Validator
subclasses. I even imagine/suggest that you can generate "schema schema" using the annotation from those decorators, which could be used in the
yaml_schema_data = strictyaml.load(yaml_schema_str, strictyaml.SCHEMA_SCHEMA)
call.
Defining schema in Python is, of course, more concise, but in my use case, I need the ability to give the end-user a way to describe schema without resorting to Python programming, following the rule of least power.
from strictyaml.
Yes, I'd like to do this feature like so::
data = strictyaml.load(yaml_str, Kwalify(kwalify_schema_str))
Defining schema in Python is, of course, more concise, but in my use case, I need the ability to give the end-user a way to describe schema without resorting to Python programming, following the rule of least power.
Sure, I think YAML is sometimes better provided it can represent the schema you need.
from strictyaml.
I'm not sure if constructing the kwalify schema from data belongs in this library though. That might work better as a separate library (especially since it's very edge-casey).
from strictyaml.
On second thoughts, I think I'm going to close this. I think it's a decent enough idea in principle, but:
-
In all the time I've been dogfooding this library, I haven't really felt the desire to use kwalify (or something similarly turing incomplete) instead. By contrast this library exists because I was almost instantly frustrated by kwalify's limitations when I first used it. I'm not 100% convinced, but I'm edging around to the view that turing completeness is needed in schemas frequently enough that it should be the default.
-
If I'm wrong about that (quite possible), I still think if it did exist it would work better as a separate library that generates a strictyaml validator from a kwalify YAML string.
If somebody else builds this as a separate library I'll be more than happy to point people to it in the README and docs.
from strictyaml.
Related Issues (20)
- Problem loading document with a single string
- Repeated revalidate() raises Invalid state HOT 2
- Failed revalidation leads to inconsistant state
- Fasjo HOT 3
- Website fails to acknowledge that the Norway problem was fixed in YAML 1.2 HOT 2
- strictyaml does not act as "a near-drop in replacement for pyyaml" HOT 4
- The type order of optional arguments affects the results HOT 2
- Date vs Datetime HOT 2
- Support python2.7.18 HOT 2
- 1.7.0 is broken (cannot import name 'ruamel' from partially initialized module 'strictyaml') HOT 5
- Map containing only Optionals does not validate an empty dict HOT 1
- as_document and load have dissimilar results for CommaSeparated(Int())
- Doesn't Work At All For Lists / Arrays? HOT 4
- New lines after comment line causes `NotImplementedError`
- Feature request/Question: "Optionalize" maps HOT 1
- Thoughts regarding case-sensitivity of keys HOT 6
- Why not: non-Turing complete configuration languages
- Cannot iterate on emtpy list
- BUG: MapCombined documentation different traceback
- Feature: strictyaml.scalar.Time
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strictyaml.