always-list-field


Namealways-list-field JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/szymansd/marshmallow-always-list-field
SummaryEnsure that your schema field will be a list
upload_time2023-10-22 21:55:30
maintainer
docs_urlNone
authorDominik Szymanski
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Dominik Szymanski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords marshmallow list fields
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # marshmallow-always-list-field
This is a small package that will ensure that your marshmallow will alway contain list.

Some times you want to ensure that your marshmallow schema will always return a list, even if the input is a single item. Just to make an API response consistent.

## Installation
```bash
pip install marshmallow-always-list-field
```

## Usage
```python
from marshmallow_always_list_field import AlwaysListField

class MySchema(Schema):
    my_list = AlwaysListField(fields.String())
```

If input is:
```python
{
    "my_list": "foo"
}
```

it will result with:
```python
{
    "my_list": ["foo"]
}
```

This will work with nested fields as well.

If nested field is:
```python
class NestedSchema(Schema):
    my_list = AlwaysListField(fields.String())

class MySchema(Schema):
    nested = fields.Nested(NestedSchema)
```

and input is:
```python
{
    "nested": {
        "my_list": "foo"
    }
}
```

result will be:
```python
{
    "nested": {
        "my_list": ["foo"]
    }
}
```

Additionally you can do something like this:

```python
class NestedSchema(Schema):
    data = fields.String()

class SampleSchema(Schema):
    nested = AlwaysListField(fields.Nested(NestedSchema))

assert result == {"nested": [{"data": "hello"}]}
```

and input is:
```python
{
    "nested": {
        "data": "hello"
    }
}
```

result will be:
```python
{
    "nested": [{"data": "hello"}]
}
```

## Development
```bash
pip install -r requirements.txt
```

## Testing
```bash
pytest
```

## License
MIT

## Author
Dominik Szymanski

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/szymansd/marshmallow-always-list-field",
    "name": "always-list-field",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "marshmallow,list,fields",
    "author": "Dominik Szymanski",
    "author_email": "Dominik Szymanski <info@realpython.com>",
    "download_url": "https://files.pythonhosted.org/packages/67/be/d9df8f7757092da73a8d6bf6879ffeb0a448d0ad87b91ed2cd1806089c88/always-list-field-1.0.0.tar.gz",
    "platform": null,
    "description": "# marshmallow-always-list-field\nThis is a small package that will ensure that your marshmallow will alway contain list.\n\nSome times you want to ensure that your marshmallow schema will always return a list, even if the input is a single item. Just to make an API response consistent.\n\n## Installation\n```bash\npip install marshmallow-always-list-field\n```\n\n## Usage\n```python\nfrom marshmallow_always_list_field import AlwaysListField\n\nclass MySchema(Schema):\n    my_list = AlwaysListField(fields.String())\n```\n\nIf input is:\n```python\n{\n    \"my_list\": \"foo\"\n}\n```\n\nit will result with:\n```python\n{\n    \"my_list\": [\"foo\"]\n}\n```\n\nThis will work with nested fields as well.\n\nIf nested field is:\n```python\nclass NestedSchema(Schema):\n    my_list = AlwaysListField(fields.String())\n\nclass MySchema(Schema):\n    nested = fields.Nested(NestedSchema)\n```\n\nand input is:\n```python\n{\n    \"nested\": {\n        \"my_list\": \"foo\"\n    }\n}\n```\n\nresult will be:\n```python\n{\n    \"nested\": {\n        \"my_list\": [\"foo\"]\n    }\n}\n```\n\nAdditionally you can do something like this:\n\n```python\nclass NestedSchema(Schema):\n    data = fields.String()\n\nclass SampleSchema(Schema):\n    nested = AlwaysListField(fields.Nested(NestedSchema))\n\nassert result == {\"nested\": [{\"data\": \"hello\"}]}\n```\n\nand input is:\n```python\n{\n    \"nested\": {\n        \"data\": \"hello\"\n    }\n}\n```\n\nresult will be:\n```python\n{\n    \"nested\": [{\"data\": \"hello\"}]\n}\n```\n\n## Development\n```bash\npip install -r requirements.txt\n```\n\n## Testing\n```bash\npytest\n```\n\n## License\nMIT\n\n## Author\nDominik Szymanski\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Dominik Szymanski  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Ensure that your schema field will be a list",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/szymansd/marshmallow-always-list-field"
    },
    "split_keywords": [
        "marshmallow",
        "list",
        "fields"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be1034ec1ab8044ca479606e1a7a6158a04ad36e2bd1bc6dbf2e6acd9320c160",
                "md5": "50d06f151ba74290ea626a6f6b33567d",
                "sha256": "f0c945836626dff43cc782ce28c858086e80740184af8aca750e88dae27e6602"
            },
            "downloads": -1,
            "filename": "always_list_field-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "50d06f151ba74290ea626a6f6b33567d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4954,
            "upload_time": "2023-10-22T21:55:29",
            "upload_time_iso_8601": "2023-10-22T21:55:29.033650Z",
            "url": "https://files.pythonhosted.org/packages/be/10/34ec1ab8044ca479606e1a7a6158a04ad36e2bd1bc6dbf2e6acd9320c160/always_list_field-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "67bed9df8f7757092da73a8d6bf6879ffeb0a448d0ad87b91ed2cd1806089c88",
                "md5": "e2b04db07503bd96dbfba33c569626c3",
                "sha256": "1f6da0dc49632d91cb168ffe1b0207e26951c1c190cf678540251ec51ffeef08"
            },
            "downloads": -1,
            "filename": "always-list-field-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e2b04db07503bd96dbfba33c569626c3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4079,
            "upload_time": "2023-10-22T21:55:30",
            "upload_time_iso_8601": "2023-10-22T21:55:30.849005Z",
            "url": "https://files.pythonhosted.org/packages/67/be/d9df8f7757092da73a8d6bf6879ffeb0a448d0ad87b91ed2cd1806089c88/always-list-field-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-22 21:55:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "szymansd",
    "github_project": "marshmallow-always-list-field",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "always-list-field"
}
        
Elapsed time: 0.13017s