Skip to main content

OwlMixin

pypi versions Actions Status codecov license

(゚∀゚) v5.0 have breaking changes
  • TIterator#group_by
    • Return TDict[TList[T]] instead of TDict[TIterator[T]]
(゚∀゚) v4.0 have breaking changes
  • 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

💪 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

pip install owlmixin

📜 API Reference

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

👉 Examples

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.

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...

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

# 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

make release version=x.y.z

Metadata

Release files for owlmixin 7.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for owlmixin 7.0.1
File Size Uploaded Provenance
owlmixin-7.0.1.tar.gz 155.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for owlmixin 7.0.1
File Interpreter ABI Platform
owlmixin-7.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 176.3 kB

Release files / owlmixin-7.0.1.tar.gz

Download URL owlmixin-7.0.1.tar.gz
Size 155.8 kB
Tags Source
SHA-256 checksum
How to use checksums
de153f701299aeed06078e51140a49d287dcf57ae0a095a01a160f57bc5abc93
BLAKE2b-256 checksum
How to use checksums
00916d46a74a3dccf38f6dd9f9422868193962e10320ca6b15c787d391059beb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.14

Release files / owlmixin-7.0.1-py3-none-any.whl

Download URL owlmixin-7.0.1-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eae5983bbf6325c744ef54ce2916da18f01f171f3c4d3c4f243fc335b6c68f8f
BLAKE2b-256 checksum
How to use checksums
13471a8288fb24252ddad567cf3c54595880a1a2c05e2ab87ca3a560ae681fd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.14

Security for owlmixin 7.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

7.0.1 This release

2 release files No provenance

1.0.0rc10

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page