Questions tagged [colander]

Colander is a simple framework for validating, serializing and deserializing of data obtained via XML, JSON, an HTML form post or any other equally simple data structure.

The colander python package allows you to:

  • Define a schema declaratively (as a series of Python classes), or imperatively (with a series of function calls).
  • Deserialize a structure of simple types (sequences, mappings, numbers, strings) to produce objects conforming to your schema. The input is validated automatically.
  • Serialize objects conforming to the schema to a simple python structure, suitable for conversion to JSON, XML or HTML form data.

Colander is a good basis for form generation systems, data description systems, and configuration systems.

72 questions
3
votes
1 answer

Using Colander to validate PATCH requests

EDIT: My original question refered to PUT requests, I have changed it to PATCH based on the answer provided by thecoshman. I am developing a RESTful webservice using cornice and I have recently discovered colander. My question is related to PATCH…
Graeme Stuart
  • 5,837
  • 2
  • 26
  • 46
3
votes
1 answer

Deserialize a top level list with Colander in Pyramid using Cornice

Given a POST request with Content-Type: application/json and a body of ["foo", "bar"] how do I create a Colander schema in Pyramid using Cornice to deserialize this. This is what I've come up with: class SimpleList(colander.SequenceSchema): …
Dan P.
  • 1,433
  • 1
  • 16
  • 28
3
votes
2 answers

Which one is the correct approach for form validation ? Colander's Schema validation or Deform's form validation?

I have just started using Pyramid for one of my projects and I have a case where in I need to validate a form field input, by taking that form field value and making a web-service call to assert the value's correctness. Like for example there is a…
Nanda Kishore
  • 2,789
  • 5
  • 38
  • 61
3
votes
3 answers

Colander: how do I allow None values?

Say I have a simple schema: class MySchema(colander.MappingSchema): thing = colander.SchemaNode(colander.Int()) With the schema above, when trying to deserialize {'thing': None} I get the error: Invalid: {'thing': u'Required'} It looks like…
Jules Olléon
  • 6,733
  • 6
  • 37
  • 47
3
votes
1 answer

Rename deseralized fields in Colander

I'm using Colander to convert JSON strings to Python Objects and vice versa in a Pyramid/Cornice based project. Is there any way that you can serialize/deserialize to different names/keys ? Here is the Colander Schema: class…
Majid
  • 2,845
  • 3
  • 15
  • 14
3
votes
1 answer

Colander and Cornice doesn't work properly

I try add schema validation as it describe in official cornice doc and the do that through decorator like service_name.post(schema=SomeSchemaClass) but it's doesn't work import colander class TrackSchema(colander.MappingSchema): genre =…
Denis
  • 7,127
  • 8
  • 37
  • 58
3
votes
1 answer

How to edit a existing record with ColanderAlchemy?

I have a SQLAlchemy model like this: class Group(Base): __tablename__ = 'groups' id = Column(Integer, primary_key = True, ca_include = True) name = Column(String, ca_include = True) class User(Base): __tablename__ = 'users' id…
Lingfeng Xiong
  • 1,131
  • 2
  • 9
  • 25
2
votes
3 answers

read Colander Schema from a config file or database

I googled for a while but I could not find reference on how to retrieve a Colander Schema from a config file or from a database. I think this is not difficult to implement but I might have overlooked something. Maybe somebody has done or seen…
moin moin
  • 2,263
  • 5
  • 32
  • 51
2
votes
1 answer

How to do simple value check with error message in Deform/Colander

I'm implementing a simple 'tick to agree to terms and conditions box' in Deform/Colander. So, I simply want to check that the box is checked and have an error message saying 'You must agree to T&C'. I understand that I can…
somewhatoff
  • 971
  • 1
  • 11
  • 25
2
votes
4 answers

How to write a regular expression in Python that accepts alphabets, numbers and a few selected special characters(,.-|;!_?)?

A Regular Expression in Python that accepts letters,numbers and only these special characters (,.-|;!_?). I have tried solving the problem through the following regular expressions but it didn't…
2
votes
1 answer

Save deform.FileData schema node as file

My script is exactly as the Deform File Upload Widget example: @view_config(renderer='templates/form.pt', name='file') @demonstrate('File Upload Widget') def file(self): class Schema(colander.Schema): upload = colander.SchemaNode( …
Joost Döbken
  • 3,450
  • 2
  • 35
  • 79
2
votes
1 answer

Validating React forms with Cornice/Colander/Pyramid

We are using Cornice for server-side REST API. Frontend is using React. We'd like to have frontend forms to post to Cornice and give proper validation results. Are there any standard practices of form submission / error result format Are there any…
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
2
votes
1 answer

Colander deform file upload widget

I want to upload a single file with the following colander schema: import colander import deform from deform.interfaces import FileUploadTempStore @view_config(route_name='upload', renderer='templates/upload.pt', …
Joost Döbken
  • 3,450
  • 2
  • 35
  • 79
2
votes
1 answer

Manipulating validated data in Colander SchemaNode

I have a set of Colander SchemaNodes used with Pyramid/Cornice in an API. For some querystring args, a range is passed (ie time=X-Y means a time range from X to Y where X and Y are integers representing epochs). I currently validate this with a…
hamx0r
  • 4,081
  • 1
  • 33
  • 46
2
votes
1 answer

Dependent/Cascading inputs using Deform

I'm trying to do a series of dependent inputs with Deform / Colander / Chameleon / Pyramid and can't find any examples. e.g. Dropdown of Country yields-> Dropdown of State or Province or Division ..etc.. yields-> Dropdown of County or City ... might…
Still.Tony
  • 1,437
  • 12
  • 35