How to use the marshmallow.fields.Int 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 / apispec / tests / test_ext_marshmallow_openapi.py View on Github external
assert res[1]["name"] == "name"
        assert res[1]["in"] == "query"

    def test_raises_error_if_not_a_schema(self, openapi):
        class NotASchema:
            pass

        expected_error = "{!r} doesn't have either `fields` or `_declared_fields`".format(
            NotASchema
        )
        with pytest.raises(ValueError, match=expected_error):
            openapi.schema2jsonschema(NotASchema)


class CategorySchema(Schema):
    id = fields.Int()
    name = fields.Str(required=True)
    breed = fields.Str(dump_only=True)


class PageSchema(Schema):
    offset = fields.Int()
    limit = fields.Int()


class PetSchema(Schema):
    category = fields.Nested(CategorySchema, many=True)
    name = fields.Str()


class TestNesting:
    def test_schema2jsonschema_with_nested_fields(self, spec_fixture):
github PrefectHQ / prefect / tests / serialization / test_versioned_schemas.py View on Github external
def test_nested_schema_does_not_create_object():
    class TestObject:
        def __init__(self, y, nested=None):
            self.x = x
            self.nested = nested

    @version("0")
    class Schema(VersionedSchema):
        class Meta:
            object_class = TestObject

        x = marshmallow.fields.Int()
        nested = marshmallow.fields.Nested("self", allow_none=True)

    deserialized = Schema().load({"x": "1", "nested": {"x": "2"}}, create_object=False)
    assert deserialized == {"x": 1, "nested": {"x": 2}}
github klen / flask-restler / tests / test_peewee.py View on Github external
def convert_BooleanField(self, field, validate=None, **params):
            return ma.fields.Int(**params)
github bcgov / queue-management / api / app / schemas / theq / channel_schema.py View on Github external
See the License for the specific language governing permissions and
limitations under the License.'''

import toastedmarshmallow
from marshmallow import fields
from app.models.theq import Channel
from qsystem import ma


class ChannelSchema(ma.ModelSchema):

    class Meta:
        model = Channel
        jit = toastedmarshmallow.Jit

    channel_id = fields.Int(dump_only=True)
    channel_name = fields.Str()
github hyperledger / aries-cloudagent-python / aries_cloudagent / protocols / issue_credential / v1_0 / routes.py View on Github external
)
        ),
        description=(
            "Credential revocation ids by revocation registry id: omit for all, "
            "specify null or empty list for all pending per revocation registry"
        ),
    )


class RevokeQueryStringSchema(Schema):
    """Parameters and validators for revocation request."""

    rev_reg_id = fields.Str(
        description="Revocation registry identifier", required=True, **INDY_REV_REG_ID,
    )
    cred_rev_id = fields.Int(
        description="Credential revocation identifier", required=True, **NATURAL_NUM,
    )
    publish = fields.Boolean(
        description=(
            "(True) publish revocation to ledger immediately, or "
            "(False) mark it pending (default value)"
        ),
        required=False,
    )


class CredIdMatchInfoSchema(Schema):
    """Path parameters and validators for request taking credential id."""

    credential_id = fields.Str(
        description="Credential identifier", required=True, example=UUIDFour.EXAMPLE
github Liu3420175 / flask_web / app / models / serialization.py View on Github external
id = fields.Int()
    name_zh = fields.Str()
    name_en = fields.Str()
    short_name = fields.Str()
    area = fields.Str()


class CitySchema(Schema):
    """
    City序列化
    """
    city_id = fields.Int()
    city_zh = fields.Str()
    city_en = fields.Str()
    city_pinyin = fields.Str()
    country_id = fields.Int()
    search_heat = fields.Int()
    country = fields.Nested(CountrySchema,only=["name_zh","name_en"])


class SupplierSchema(Schema):
    """
    
    """
    id = fields.Int()
    name = fields.Str()
    country_id = fields.Int()
    country = fields.Nested(CountrySchema, only=["name_zh", "name_en"])


class OperatorSchema(Schema):
    """
github f0cker / crackq / crackq / cq_api.py View on Github external
rules = fields.List(fields.String(validate=[StringContains(r'[\W]\-'),
                                                Length(min=1, max=60)]),
                        allow_none=True)
    username = fields.Bool(allow_none=True)
    notify = fields.Bool(allow_none=True)
    increment = fields.Bool(allow_none=True)
    disable_brain = fields.Bool(allow_none=True)
    incement_min = fields.Int(allow_none=True, validate=Range(min=0, max=20))
    increment_max = fields.Int(allow_none=True, validate=Range(min=0, max=20))
    mask = fields.Str(allow_none=True, validate=StringContains(r'[^aldsu\?0-9a-zA-Z]'))
    mask_file = fields.List(fields.String(validate=[StringContains(r'[\W]\-'),
                                                    Length(min=1, max=60)]),
                                allow_none=True)
    name = fields.Str(allow_none=True, validate=StringContains(r'[\W]'), error_messages=error_messages)
    hash_mode = fields.Int(allow_none=False, validate=Range(min=0, max=65535))
    restore = fields.Int(validate=Range(min=0, max=1000000000000))
    user = fields.Str(allow_none=False, validate=StringContains(r'[\W]'))
    password = fields.Str(allow_none=False, validate=StringContains(r'[^\w\!\@\#\$\%\^\&\*\(\)\-\+\.\,\\\/]'))


def get_jobdetails(job_details):
    """
    Function to help pull only required information from a specified redis job
    description string.
    job_details: str
                string returned from rq.job.description

    Returns
    ------
    deets_dict: dictionary
                only the specified job details are returned
github polyaxon / polyaxon / polyaxon / hpsearch / schemas / hyperband.py View on Github external
from marshmallow import fields, post_dump, post_load, validate

from hpsearch.schemas.base_iteration import BaseIterationConfig, BaseIterationSchema


class HyperbandIterationSchema(BaseIterationSchema):
    bracket_iteration = fields.Int()
    experiments_metrics = fields.List(fields.List(fields.Raw(), validate=validate.Length(equal=2)),
                                      allow_none=True)

    @post_load
    def make(self, data):
        return HyperbandIterationConfig(**data)

    @post_dump
    def unmake(self, data):
        return HyperbandIterationConfig.remove_reduced_attrs(data)


class HyperbandIterationConfig(BaseIterationConfig):
    SCHEMA = HyperbandIterationSchema

    def __init__(self,
github lkorigin / laniakea / src / laniakea / db / debcheck.py View on Github external
import json
from sqlalchemy import Column, Text, String, Integer, DateTime, Enum, ForeignKey
from sqlalchemy.orm import relationship, backref
from sqlalchemy.dialects.postgresql import JSON, ARRAY
from marshmallow import Schema, fields, EXCLUDE
from uuid import uuid4
from datetime import datetime
from .base import Base, UUID, DebVersion
from .archive import PackageType


class PackageIssue(Schema):
    '''
    Information about the package issue reason.
    '''
    package_type = fields.Int()  # PackageType enum
    package_name = fields.Str()
    package_version = fields.Str()
    architecture = fields.Str()

    depends = fields.Str()
    unsat_dependency = fields.Str()
    unsat_conflict = fields.Str()

    class Meta:
        unknown = EXCLUDE


class PackageConflict(Schema):
    '''
    Information about a conflict between packages.
    '''
github polyaxon / polyaxon / polyaxon_schemas / ml / processing / pipelines.py View on Github external
from marshmallow import EXCLUDE, fields

from polyaxon_schemas.base import BaseConfig, BaseMultiSchema, BaseSchema
from polyaxon_schemas.ml.processing.feature_processors import FeatureProcessorsSchema


class BasePipelineSchema(BaseSchema):
    name = fields.Str(allow_none=True)
    feature_processors = fields.Nested(FeatureProcessorsSchema, allow_none=True)
    shuffle = fields.Bool(allow_none=True)
    num_epochs = fields.Int(allow_none=True)
    batch_size = fields.Int(allow_none=True)
    bucket_boundaries = fields.List(fields.Int(), allow_none=True)
    allow_smaller_final_batch = fields.Bool(allow_none=True)
    dynamic_pad = fields.Bool(allow_none=True)
    min_after_dequeue = fields.Int(allow_none=True)
    num_threads = fields.Int(allow_none=True)
    capacity = fields.Int(allow_none=True)

    @staticmethod
    def schema_config():
        return BasePipelineConfig


class BasePipelineConfig(BaseConfig):
    """Abstract InputPipeline class. All input pipelines must inherit from this.
    An InputPipeline defines how data is read, parsed, and separated into
    features and labels.

    Args:
        name: `str`, name to give for this pipeline.
        feature_processors: `dict`, list of modules to call for each feature to be processed.