Name | owlmixin JSON |
Version |
7.0.1
JSON |
| download |
home_page | None |
Summary | Mixin which converts ``data class instance`` and others each other more simple. |
upload_time | 2025-01-03 07:29:44 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
dict
json
mixin
parser
yaml
|
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
* uv
* make
### Flow
1. Development on master and if you need branches and issues, create them
2. Use the [Conventional Commits] message
### Commands
```bash
# Create env
$ uv run
# Build documentation and run server locally
$ make serve-docs
# Test (Doc test & Unit test)
$ make test
```
## 📦 Release
https://github.com/tadashi-aikawa/owlmixin/actions/workflows/release.yaml?query=workflow%3ARelease
### (Appendix) Another way
If you can't or don't want to use GitHub Actions, you can release locally as following.
#### (a1) Requirements
* **Windows is not supported!!!**
* uv (with pypi authentications)
* make
#### (a2) Commands
```bash
make release version=x.y.z
```
[ghr]: https://github.com/tcnksm/ghr
[Conventional Commits]: https://www.conventionalcommits.org/ja/v1.0.0/
Raw data
{
"_id": null,
"home_page": null,
"name": "owlmixin",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "dict, json, mixin, parser, yaml",
"author": null,
"author_email": "tadashi-aikawa <syou.maman@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/00/91/6d46a74a3dccf38f6dd9f9422868193962e10320ca6b15c787d391059beb/owlmixin-7.0.1.tar.gz",
"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* uv\n* make\n\n### Flow\n\n1. Development on master and if you need branches and issues, create them\n2. Use the [Conventional Commits] message\n\n### Commands\n\n```bash\n# Create env\n$ uv run\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\nhttps://github.com/tadashi-aikawa/owlmixin/actions/workflows/release.yaml?query=workflow%3ARelease\n\n### (Appendix) Another way\n\nIf you can't or don't want to use GitHub Actions, you can release locally as following.\n\n#### (a1) Requirements\n\n* **Windows is not supported!!!**\n* uv (with pypi authentications)\n* make\n\n#### (a2) Commands\n\n```bash\nmake release version=x.y.z\n```\n\n\n[ghr]: https://github.com/tcnksm/ghr\n[Conventional Commits]: https://www.conventionalcommits.org/ja/v1.0.0/\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Mixin which converts ``data class instance`` and others each other more simple.",
"version": "7.0.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",
" mixin",
" parser",
" yaml"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "13471a8288fb24252ddad567cf3c54595880a1a2c05e2ab87ca3a560ae681fd8",
"md5": "26dab7b8ce0feef1c0e6d8081733a075",
"sha256": "eae5983bbf6325c744ef54ce2916da18f01f171f3c4d3c4f243fc335b6c68f8f"
},
"downloads": -1,
"filename": "owlmixin-7.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "26dab7b8ce0feef1c0e6d8081733a075",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 20538,
"upload_time": "2025-01-03T07:29:42",
"upload_time_iso_8601": "2025-01-03T07:29:42.074729Z",
"url": "https://files.pythonhosted.org/packages/13/47/1a8288fb24252ddad567cf3c54595880a1a2c05e2ab87ca3a560ae681fd8/owlmixin-7.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "00916d46a74a3dccf38f6dd9f9422868193962e10320ca6b15c787d391059beb",
"md5": "b294ae60b1bd042276fdd1f7675352f9",
"sha256": "de153f701299aeed06078e51140a49d287dcf57ae0a095a01a160f57bc5abc93"
},
"downloads": -1,
"filename": "owlmixin-7.0.1.tar.gz",
"has_sig": false,
"md5_digest": "b294ae60b1bd042276fdd1f7675352f9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 155785,
"upload_time": "2025-01-03T07:29:44",
"upload_time_iso_8601": "2025-01-03T07:29:44.291882Z",
"url": "https://files.pythonhosted.org/packages/00/91/6d46a74a3dccf38f6dd9f9422868193962e10320ca6b15c787d391059beb/owlmixin-7.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-03 07:29:44",
"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"
}