owlmixin


Nameowlmixin JSON
Version 6.1.1 PyPI version JSON
download
home_pagehttps://github.com/tadashi-aikawa/owlmixin
SummaryMixin which converts ``data class instance`` and others each other more simple.
upload_time2023-10-18 06:23:22
maintainer
docs_urlNone
authortadashi-aikawa
requires_python>=3.7,<4.0
licenseMIT
keywords dict json yaml parser mixin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # OwlMixin

[![pypi](https://img.shields.io/pypi/v/owlmixin.svg)](https://pypi.org/project/owlmixin/)
[![versions](https://img.shields.io/pypi/pyversions/owlmixin.svg)](https://pypi.org/project/owlmixin/)
[![Actions Status](https://github.com/tadashi-aikawa/owlmixin/workflows/Tests/badge.svg)](https://github.com/tadashi-aikawa/owlmixin/actions)
[![codecov](https://codecov.io/gh/tadashi-aikawa/owlmixin/branch/master/graph/badge.svg)](https://codecov.io/gh/tadashi-aikawa/owlmixin)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()


<details>
    <summary><b>(゚∀゚) v5.0 have breaking changes</b></summary>
    <div>

* `TIterator#group_by`
  * Return `TDict[TList[T]]` instead of `TDict[TIterator[T]]`
    </div>
</details>

<details>
    <summary><b>(゚∀゚) v4.0 have breaking changes</b></summary>
    <div>

* `OwlMixin`
  * Must use keyword arguments in `from_XXX` and `to_XXX` except for some ones
  * `from_csvf` -> `from_csvf_to_list`
* `TList`
  * `head` -> `take`
  * `partial` -> `partition` (switch left and right)
* `transformers.XXX`
  * Must use keyword arguments in
    * `to_dict`
    * `to_dicts`
    * `to_json`
    * `to_jsonf`
    * `to_yaml`
    * `to_yamlf`
    * `to_csv`
    * `to_csvf`
    </div>
</details>


## 💪 Motivation

Have you ever wanted to write robust code in Python? This library will make such your wishes come true.

Define your data class which is extend OwlMixin, you can use some useful methods which help your codes robust.
See following `Example` and `API Reference` sections.


## 💃 Installation

```bash
pip install owlmixin
```


## 📜 API Reference

https://tadashi-aikawa.github.io/owlmixin/


## 👉 Examples

```python
from owlmixin import OwlMixin, OwlEnum, TOption, TList

class Color(OwlEnum):
    RED = "red"
    GREEN = "green"
    BLUE = "blue"

class Food(OwlMixin):
    id: int
    name: str
    color: TOption[Color]

class Human(OwlMixin):
    id: int
    name: str
    favorite: TList[Food]

jiro = Human.from_dict({
    "id": 10,
    "name": "jiro",
    "favorite": [
        {"id": 1, "name": "apple"},
        {"id": 2, "name": "orange", "color": "green"}
    ]
})
```

Then...

```
>>> jiro.id
10
>>> jiro.name
'jiro'

>>> print(jiro.to_dict())
{'id': 10, 'name': 'jiro', 'favorite': [{'id': 1, 'name': 'apple'}, {'id': 2, 'name': 'orange', 'color': 'green'}]}

>>> print(jiro.favorite[0].to_pretty_json())
{
    "id": 1,
    "name": "apple"
}

>>> print(jiro.to_yaml())
favorite:
  - id: 1
    name: apple
  - color: green
    id: 2
    name: orange
id: 10
name: jiro

>>> print(jiro.favorite.to_csv(['id', 'name', 'color'], with_header=True))
id,name,color
1,apple,
2,orange,green
```

You can also use methods chains as following.

```python
from owlmixin import OwlMixin, TOption, TIterator


class Repository(OwlMixin):
    id: int
    name: str
    description: TOption[str]
    stargazers_count: int


class GithubRepository(OwlMixin):
    total_count: int
    incomplete_results: bool
    items: TIterator[Repository]
```

Then...

```python
>>> print(
...     GithubRepository
...         .from_json_url("https://api.github.com/search/repositories?q=git")
...         .items
...         .filter(lambda x: x.stargazers_count > 100)
...         .order_by(lambda x: x.stargazers_count, True)
...         .take(5)
...         .emap(lambda v, i: {
...             'RANK': i+1,
...             'STAR': v.stargazers_count,
...             'NAME': v.name,
...             'DESCRIPTION': v.description
...         })
...         .to_csv(fieldnames=["RANK", "STAR", "NAME", "DESCRIPTION"], with_header=True)
... )
RANK,STAR,NAME,DESCRIPTION
1,84643,gitignore,A collection of useful .gitignore templates
2,30456,gogs,Gogs is a painless self-hosted Git service.
3,29908,git-flight-rules,Flight rules for git
4,27704,git,Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
5,15541,tips,Most commonly used git tips and tricks.
```

Don't you think smart?


## 💻 For developers

### Requirements

* poetry
* make

### Flow

1. Development on master and if you need branches and issues, create them
2. Commit with prefix emoji such as "📝", and suffix issue number like "#120"

### Commands

```bash
# Create env
$ make init-dev

# Build documentation and run server locally
$ make serve-docs

# Test (Doc test & Unit test)
$ make test
```


## 📦 Release

### Requirements

* poetry
* make
* [ghr]

[ghr]: https://github.com/tcnksm/ghr

### Commands

```bash
make release version=x.y.z
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tadashi-aikawa/owlmixin",
    "name": "owlmixin",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "dict,json,yaml,parser,mixin",
    "author": "tadashi-aikawa",
    "author_email": "syou.maman@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "# OwlMixin\n\n[![pypi](https://img.shields.io/pypi/v/owlmixin.svg)](https://pypi.org/project/owlmixin/)\n[![versions](https://img.shields.io/pypi/pyversions/owlmixin.svg)](https://pypi.org/project/owlmixin/)\n[![Actions Status](https://github.com/tadashi-aikawa/owlmixin/workflows/Tests/badge.svg)](https://github.com/tadashi-aikawa/owlmixin/actions)\n[![codecov](https://codecov.io/gh/tadashi-aikawa/owlmixin/branch/master/graph/badge.svg)](https://codecov.io/gh/tadashi-aikawa/owlmixin)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()\n\n\n<details>\n    <summary><b>(\uff9f\u2200\uff9f) v5.0 have breaking changes</b></summary>\n    <div>\n\n* `TIterator#group_by`\n  * Return `TDict[TList[T]]` instead of `TDict[TIterator[T]]`\n    </div>\n</details>\n\n<details>\n    <summary><b>(\uff9f\u2200\uff9f) v4.0 have breaking changes</b></summary>\n    <div>\n\n* `OwlMixin`\n  * Must use keyword arguments in `from_XXX` and `to_XXX` except for some ones\n  * `from_csvf` -> `from_csvf_to_list`\n* `TList`\n  * `head` -> `take`\n  * `partial` -> `partition` (switch left and right)\n* `transformers.XXX`\n  * Must use keyword arguments in\n    * `to_dict`\n    * `to_dicts`\n    * `to_json`\n    * `to_jsonf`\n    * `to_yaml`\n    * `to_yamlf`\n    * `to_csv`\n    * `to_csvf`\n    </div>\n</details>\n\n\n## \ud83d\udcaa Motivation\n\nHave you ever wanted to write robust code in Python? This library will make such your wishes come true.\n\nDefine your data class which is extend OwlMixin, you can use some useful methods which help your codes robust.\nSee following `Example` and `API Reference` sections.\n\n\n## \ud83d\udc83 Installation\n\n```bash\npip install owlmixin\n```\n\n\n## \ud83d\udcdc API Reference\n\nhttps://tadashi-aikawa.github.io/owlmixin/\n\n\n## \ud83d\udc49 Examples\n\n```python\nfrom owlmixin import OwlMixin, OwlEnum, TOption, TList\n\nclass Color(OwlEnum):\n    RED = \"red\"\n    GREEN = \"green\"\n    BLUE = \"blue\"\n\nclass Food(OwlMixin):\n    id: int\n    name: str\n    color: TOption[Color]\n\nclass Human(OwlMixin):\n    id: int\n    name: str\n    favorite: TList[Food]\n\njiro = Human.from_dict({\n    \"id\": 10,\n    \"name\": \"jiro\",\n    \"favorite\": [\n        {\"id\": 1, \"name\": \"apple\"},\n        {\"id\": 2, \"name\": \"orange\", \"color\": \"green\"}\n    ]\n})\n```\n\nThen...\n\n```\n>>> jiro.id\n10\n>>> jiro.name\n'jiro'\n\n>>> print(jiro.to_dict())\n{'id': 10, 'name': 'jiro', 'favorite': [{'id': 1, 'name': 'apple'}, {'id': 2, 'name': 'orange', 'color': 'green'}]}\n\n>>> print(jiro.favorite[0].to_pretty_json())\n{\n    \"id\": 1,\n    \"name\": \"apple\"\n}\n\n>>> print(jiro.to_yaml())\nfavorite:\n  - id: 1\n    name: apple\n  - color: green\n    id: 2\n    name: orange\nid: 10\nname: jiro\n\n>>> print(jiro.favorite.to_csv(['id', 'name', 'color'], with_header=True))\nid,name,color\n1,apple,\n2,orange,green\n```\n\nYou can also use methods chains as following.\n\n```python\nfrom owlmixin import OwlMixin, TOption, TIterator\n\n\nclass Repository(OwlMixin):\n    id: int\n    name: str\n    description: TOption[str]\n    stargazers_count: int\n\n\nclass GithubRepository(OwlMixin):\n    total_count: int\n    incomplete_results: bool\n    items: TIterator[Repository]\n```\n\nThen...\n\n```python\n>>> print(\n...     GithubRepository\n...         .from_json_url(\"https://api.github.com/search/repositories?q=git\")\n...         .items\n...         .filter(lambda x: x.stargazers_count > 100)\n...         .order_by(lambda x: x.stargazers_count, True)\n...         .take(5)\n...         .emap(lambda v, i: {\n...             'RANK': i+1,\n...             'STAR': v.stargazers_count,\n...             'NAME': v.name,\n...             'DESCRIPTION': v.description\n...         })\n...         .to_csv(fieldnames=[\"RANK\", \"STAR\", \"NAME\", \"DESCRIPTION\"], with_header=True)\n... )\nRANK,STAR,NAME,DESCRIPTION\n1,84643,gitignore,A collection of useful .gitignore templates\n2,30456,gogs,Gogs is a painless self-hosted Git service.\n3,29908,git-flight-rules,Flight rules for git\n4,27704,git,Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.\n5,15541,tips,Most commonly used git tips and tricks.\n```\n\nDon't you think smart?\n\n\n## \ud83d\udcbb For developers\n\n### Requirements\n\n* poetry\n* make\n\n### Flow\n\n1. Development on master and if you need branches and issues, create them\n2. Commit with prefix emoji such as \"\ud83d\udcdd\", and suffix issue number like \"#120\"\n\n### Commands\n\n```bash\n# Create env\n$ make init-dev\n\n# Build documentation and run server locally\n$ make serve-docs\n\n# Test (Doc test & Unit test)\n$ make test\n```\n\n\n## \ud83d\udce6 Release\n\n### Requirements\n\n* poetry\n* make\n* [ghr]\n\n[ghr]: https://github.com/tcnksm/ghr\n\n### Commands\n\n```bash\nmake release version=x.y.z\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Mixin which converts ``data class instance`` and others each other more simple.",
    "version": "6.1.1",
    "project_urls": {
        "Documentation": "https://tadashi-aikawa.github.io/owlmixin/",
        "Homepage": "https://github.com/tadashi-aikawa/owlmixin",
        "Repository": "https://github.com/tadashi-aikawa/owlmixin"
    },
    "split_keywords": [
        "dict",
        "json",
        "yaml",
        "parser",
        "mixin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c6ffbc0474ad50456ca587d5e80c4b013b9c5adaf795f0d619fe95948f794d1",
                "md5": "5ada0ea141ea999a8ef0d22af1bea4e6",
                "sha256": "b7dc22b805b50fae5566a4c884ac5aa7b606a347ae734d55495b20787dac011c"
            },
            "downloads": -1,
            "filename": "owlmixin-6.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5ada0ea141ea999a8ef0d22af1bea4e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 20321,
            "upload_time": "2023-10-18T06:23:22",
            "upload_time_iso_8601": "2023-10-18T06:23:22.466027Z",
            "url": "https://files.pythonhosted.org/packages/2c/6f/fbc0474ad50456ca587d5e80c4b013b9c5adaf795f0d619fe95948f794d1/owlmixin-6.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-18 06:23:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tadashi-aikawa",
    "github_project": "owlmixin",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "owlmixin"
}
        
Elapsed time: 0.12324s