Questions tagged [marshmallow]

Marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes. (For Questions about Android Marshmallow use the tag [android-6.0-marshmallow].)

Marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes. See https://marshmallow.readthedocs.io/en/latest/index.html

589 questions
11
votes
1 answer

ValidationError on Flask-Marshmallow schema

I'm creating a simple web api with flask and sqlalchemy with marshmallow as serializer, and here is UserModel. class UserModel(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key = True) username =…
pl-jay
  • 970
  • 1
  • 16
  • 33
11
votes
1 answer

Handling multiple variants of a marshmallow schema

I have a simple Flask-SQLAlchemy model, which I'm writing a REST API for: class Report(db.Model, CRUDMixin): report_id = Column(Integer, primary_key=True) user_id = Column(Integer, ForeignKey('users.user_id'), index=True) report_hash =…
Migwell
  • 18,631
  • 21
  • 91
  • 160
10
votes
2 answers

How to use Marshmallow Schema in Flask-restx Swagger UI Automatically

I'm trying to create a restful web services with flask-restx and marshmallow. I'm using marshmallow for both request and response validations. Since flask-restx api docs does not support marshmallow schemas in swagger ui, i want to add it using doc…
Angus G.
  • 79
  • 1
  • 6
10
votes
1 answer

How to define Python Enum properties if MySQL ENUM values have space in their names?

I have Python Enum class like this: from enum import Enum class Seniority(Enum): Intern = "Intern" Junior_Engineer = "Junior Engineer" Medior_Engineer = "Medior Engineer" Senior_Engineer = "Senior Engineer" In MYSQL database,…
Matija Lukic
  • 599
  • 8
  • 28
10
votes
3 answers

Flask Marshmallow JSON fields

I have defined a POST call would that needs data: { "one" : "hello", "two" : "world", "three" : { "ab": "123", "cd": false } } For this, I am able to define one and two, but unsure what…
rgamber
  • 5,749
  • 10
  • 55
  • 99
10
votes
2 answers

Apply JSON Schema with Marshmallow Serialization

I am using Marshmallow for serialization and de-serialization of JSON strings. From the Marshmallow API Docs (https://marshmallow.readthedocs.io/en/3.0/api_reference.html), it looks like you have specify a list of fields (and, unless using Meta)…
Josh
  • 1,155
  • 4
  • 12
  • 21
10
votes
1 answer

marshmallow flatten nested objects

I have objects that look a little something like: source = { id: 123, objects: [ { random_data: aaaa, actual_data: { useful: 111, ... } }, { random_data: bbbb, actual_data: { …
user2420591
10
votes
2 answers

Difficulty serializing Geography column type using sqlalchemy marshmallow

I an trying to use Marshmallow to do do deserialize and serialise SQLAlchemy objects but run into a problem when dealing with Geography fields in the ORM. Firstly the model: class Address(db.Model, TableColumnsBase): __tablename__ = 'address' …
silverdagger
  • 1,124
  • 13
  • 37
9
votes
1 answer

How to add multiple validation parameters in a marshmallow schema

I have the following schema in one of my class models: class SocialMediaSchema(Schema): facebook_profile_url = fields.String(required=False, validate=validate.Length(0, 71, 'Facebook username is too long.') Aside from validating the length, I…
Bargain23
  • 1,863
  • 3
  • 29
  • 50
9
votes
1 answer

Need a way to get python object from marshmallow load function instead of dictionary without using post_load decorator

class ProfileSchema(Schema): id = fields.Integer() first_name = fields.String(required=True) last_name = fields.String() phone = fields.Str() email = fields.Email() gender = fields.String() city = fields.Str() state…
9
votes
1 answer

Serialize two nested schema with marshmallow

I am fairly new to python. I have two SQLAlchemy models as follows: class listing(db.Model): id = db.Integer(primary_key=True) title = db.String() location_id = db.Column(db.Integer, db.ForeignKey('location.id')) location =…
Sohaib Farooqi
  • 5,457
  • 4
  • 31
  • 43
9
votes
1 answer

SqlAlchemy Relationship and Marshmallow

I am trying to return JSON or even a complete string of a returned one to many sqlalchemy query. I am using Marshmallow at this point to try do it but it keeps returning incomplete data I have two models defined as : class UserModel(db.Model): …
Zee18
  • 425
  • 2
  • 5
  • 11
8
votes
1 answer

Marshmallow Schema and Class Inheritance

I am using Marshmallow for the first time and unfortunately could not find an answer on the internet. There are two classes, one inherits from the other. Both should be serialisable and deserialisable. After deserialisation they should be available…
unlimitedfox
  • 386
  • 4
  • 8
8
votes
4 answers

Python Marshmallow Field can be two different types

I want to specify a marshmallow schema. For one of my fields, I want it to be validated however it can be EITHER a string or a list of strings. I have tried the Raw field type however that is allows everything through. Is there a way to just…
Jimmy Jo
  • 121
  • 1
  • 1
  • 4
8
votes
1 answer

Serializing a sqlalchemy hybrid_property using marshmallow

I am using sqlalchemy and marshmallow in my RESTful flask application to serialize my models. I have a hybrid_property that comes from one of my relationships on that model. I would like to now serialize that hybrid_property in my schema using the…
James Russo
  • 578
  • 3
  • 18
1
2
3
39 40