Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Mixin which converts ``data class instance`` and others each other more simple.

Project description


travis coverage complexity license pypi versions

(゚∀゚) v3.0 have two breaking changes

  1. Change return types of find to TOption[T]
  2. Remove OwlEnum.from_symbol (use from_value)


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.


$ pip install owlmixin

API Reference


from owlmixin import OwlMixin
from owlmixin.owlenum import OwlEnum
from owlmixin.owloption import TOption
from owlmixin.owlcollections import 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"}


>>> 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())
  - 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))

You can also use methods chains as following.

Below sample code uses kachayev/ <>_, great package!!

>>> from owlmixin.owloption import TOption
>>> from owlmixin.owlcollections import TList
>>> from fn import _
>>> class Repository(OwlMixin):
...     id: int
...     name: str
...     description: TOption[str]
...     stargazers_count: int
>>> class GithubRepository(OwlMixin):
...     total_count: int
...     incomplete_results: bool
...     items: TList[Repository]
>>> print(
...     GithubRepository \
...         .from_json_url("") \
...         .items \
...         .filter(_.stargazers_count > 100) \
...         .order_by(_.stargazers_count, True) \
...         .head(5) \
...         .emap(lambda v, i: {
...             'RANK': i+1,
...             'STAR': v.stargazers_count,
...             'NAME':,
...             'DESCRIPTION': v.description
...         }) \
...         .to_csv(fieldnames=["RANK", "STAR", "NAME", "DESCRIPTION"], with_header=True)
... )

1,50787,gitignore,A collection of useful .gitignore templates
2,19308,gogs,Gogs is a painless self-hosted Git service.
3,17750,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.
4,10744,hub,hub helps you win at git.
5,10338,tips,Most commonly used git tips and tricks.

Don't you think smart?

For developer

Requires pipenv and make.


# Create env
$ make init

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

Version up

Before release, you need to

  1. Confirm that your branch name equals release version


$ make release

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
owlmixin-3.1.1-py3-none-any.whl (18.3 kB) Copy SHA256 hash SHA256 Wheel py3

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page