How to use the marshmallow.fields.Integer function in marshmallow

To help you get started, we’ve selected a few marshmallow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marshmallow-code / marshmallow-sqlalchemy / tests / test_conversion.py View on Github external
            (mysql.INTEGER, fields.Integer),
            (mysql.DATETIME, fields.DateTime),
        ),
    )
    def test_convert_types(self, converter, sa_type, field_type):
        prop = make_property(sa_type())
        field = converter.property2field(prop)
        assert type(field) == field_type
github podhmo / swagger-marshmallow-codegen / examples / 04github / githubschema.py View on Github external
class Commit(Schema):
    author = fields.Nested('CommitAuthor')
    commit = fields.Nested('CommitCommit')
    committer = fields.Nested('CommitCommitter')
    files = fields.List(fields.Nested('CommitFilesItem', ))
    parents = fields.List(fields.Nested('CommitParentsItem', ))
    sha = fields.String()
    stats = fields.Nested('CommitStats')
    url = fields.String()


class CommitStats(Schema):
    additions = fields.Integer()
    deletions = fields.Integer()
    total = fields.Integer()


class CommitParentsItem(Schema):
    sha = fields.String()
    url = fields.String()


class CommitFilesItem(Schema):
    additions = fields.Integer()
    blob_url = fields.String()
    changes = fields.Integer()
    deletions = fields.Integer()
    filename = fields.String()
    patch = fields.String()
    raw_url = fields.String()
github Netflix / lemur / lemur / certificates / schemas.py View on Github external
def enforce_notifications(self, data):
        """
        Ensures that when an owner changes, default notifications are added for the new owner.
        Old owner notifications are retained unless explicitly removed.
        :param data:
        :return:
        """
        if data['owner']:
            notification_name = "DEFAULT_{0}".format(data['owner'].split('@')[0].upper())
            data['notifications'] += notification_service.create_default_expiration_notifications(notification_name, [data['owner']])
        return data


class CertificateNestedOutputSchema(LemurOutputSchema):
    __envelope__ = False
    id = fields.Integer()
    name = fields.String()
    owner = fields.Email()
    creator = fields.Nested(UserNestedOutputSchema)
    description = fields.String()

    status = fields.String()

    bits = fields.Integer()
    body = fields.String()
    chain = fields.String()
    active = fields.Boolean()

    rotation = fields.Boolean()
    notify = fields.Boolean()
    rotation_policy = fields.Nested(RotationPolicyNestedOutputSchema)
github izderadicka / mybookshelf2 / app / schema.py View on Github external
def create_insert_serializer(cls):
        return PartialSchemaFactory(EbookSchema, exclude=('version_id',))
    
    @classmethod
    def create_list_serializer(cls):
        return EbookSchema(many=True, only=(
            'id', 'title', 'authors', 'series', 'series_index', 'language', 'cover', 'rating', 'rating_count'))
        
    @classmethod
    def create_update_serializer(cls):
        return PartialSchemaFactory(EbookSchema, partial=True)
    

class FileInfoSchema(Schema):
    mime_type = fields.String(required=True, validate=validate.Length(max=255))
    size = fields.Integer(required=True, validate=validate.Range(min=1))
    # hash = fields.String(validate=validate.Length(max=128))
    
class RatingSchema(Schema):
    rating = fields.Float(allow_none=True, validate=validate.Range(min=0, max=100))
    description = fields.String(validate=validate.Length(max=16*1024))
    
class BookshelfSchema(ModelSchema):
    items_count = fields.Function(serialize = lambda o: o.items_count)
    owner = fields.Function(serialize= lambda o: o.created_by.user_name)
    class Meta:
        model = model.Bookshelf
        exclude = ('items',)
        
    @classmethod
    def create_list_serializer(cls):
        return cls(many=True, only=('id', 'name',  'owner', 'description', 'items_count'))
github globality-corp / microcosm-flask / microcosm_flask / paging.py View on Github external
from microcosm_flask.linking import Link, Links


def identity(x):
    """
    Identity function.

    """
    return x


# NB: lots of code currently uses `PageSchema` to refer to `OffsetLimitPageSchema`
# keeping this (mis)naming for backwards compatibilty
class PageSchema(Schema):
    offset = fields.Integer(missing=None)
    limit = fields.Integer(missing=None)


class OffsetLimitPageSchema(PageSchema):
    pass


class PaginatedList:
    """
    A list of items with knowledge of a page.

    Includes HAL-style links (e.g for the current or next page)

    """
    def __init__(self, items, _page, _ns, _operation, _context):
        self.items = items
        self._page = _page
github nonamenix / marshmallow-jam / jam / __init__.py View on Github external
from marshmallow import fields, post_load
from marshmallow.schema import SchemaMeta as BaseSchemaMeta, BaseSchema

import datetime as dt
import uuid
import decimal


logger = logging.getLogger(__name__)


BASIC_TYPES_MAPPING = {
    str: fields.String,
    float: fields.Float,
    bool: fields.Boolean,
    int: fields.Integer,
    uuid.UUID: fields.UUID,
    decimal.Decimal: fields.Decimal,
    dt.datetime: fields.DateTime,
    dt.time: fields.Time,
    dt.date: fields.Date,
    dt.timedelta: fields.TimeDelta,
}


NoneType = type(None)
UnionType = type(typing.Union)


class JamException(Exception):
    pass
github labd / commercetools-python-sdk / src / commercetools / schemas / _channel.py View on Github external
allow_none=True,
        missing=None,
        data_key="geoLocation",
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.ChannelDraft(**data)


class ChannelPagedQueryResponseSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.ChannelPagedQueryResponse`."
    limit = marshmallow.fields.Integer(allow_none=True)
    count = marshmallow.fields.Integer(allow_none=True)
    total = marshmallow.fields.Integer(allow_none=True, missing=None)
    offset = marshmallow.fields.Integer(allow_none=True)
    results = marshmallow.fields.Nested(
        nested="commercetools.schemas._channel.ChannelSchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        many=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.ChannelPagedQueryResponse(**data)
github Ch00k / clapperboard / clapperboard / resources / common / response_fields.py View on Github external
show_end = fields.String()


MOVIE = {
    'id': fields.Integer,
    'title': fields.String,
    'url_code': fields.String,
    'show_start': fields.String,
    'show_end': fields.String,
    'imdb_data': fields.Nested(IMDB_DATA, default={})
}


SHOW_TIME = {
    'id': fields.Integer,
    'theatre_id': fields.Integer,
    'hall_id': fields.Integer,
    'technology_id': fields.Integer,
    'date_time': fields.DateTime(dt_format='iso8601'),
    'order_url': fields.String
}


THEATRE = {
    'id': fields.Integer,
    'name': fields.String,
    'en_name': fields.String,
    'url_code': fields.String,
    'st_url_code': fields.String
}
github apryor6 / flask_accepts / examples / load_dump_only.py View on Github external
from marshmallow import fields, Schema
from flask import request, Flask
from flask_restx import Api, Resource

from flask_accepts import accepts, responds


class WidgetSchema(Schema):
    id = fields.Integer()
    created_at = fields.DateTime(dump_only=True)
    foo = fields.String(load_only=True)
    baz = fields.Integer()


def create_app():
    app = Flask(__name__)
    api = Api(app)

    @api.route("/widget")
    class WidgetResource(Resource):
        @accepts(schema=WidgetSchema, api=api)
        @responds(schema=WidgetSchema, api=api)
        def post(self):
            # save data to a new record, and return ID
            return request.parsed_obj

    return app
github podhmo / swagger-marshmallow-codegen / examples / 04github / githubschema.py View on Github external
created_at = fields.String(description='ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ')
    description = fields.String()
    fork = fields.Boolean()
    forks = fields.Integer()
    forks_count = fields.Integer()
    full_name = fields.String()
    git_url = fields.String()
    homepage = fields.String()
    html_url = fields.String()
    id = fields.Integer()
    language = fields.String()
    master_branch = fields.String()
    mirror_url = fields.String()
    name = fields.String()
    open_issues = fields.Integer()
    open_issues_count = fields.Integer()
    owner = fields.Nested('ForksItemOwner')
    private = fields.Boolean()
    pushed_at = fields.String(description='ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ')
    size = fields.Integer()
    ssh_url = fields.String()
    svn_url = fields.String()
    updated_at = fields.String(description='ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ')
    url = fields.String()
    watchers = fields.Integer()
    watchers_count = fields.Integer()


class ForksItemOwner(Schema):
    avatar_url = fields.String()
    gravatar_id = fields.String()
    id = fields.Integer()