{"id":24112456,"url":"https://github.com/mletrone/maypy","last_synced_at":"2025-10-06T09:31:18.347Z","repository":{"id":256574986,"uuid":"846631010","full_name":"mLetrone/maypy","owner":"mLetrone","description":"Pythonic Java optional","archived":false,"fork":false,"pushed_at":"2025-01-10T14:53:25.000Z","size":1385,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-20T21:54:13.056Z","etag":null,"topics":["python","python3","typed","utils-library"],"latest_commit_sha":null,"homepage":"https://mletrone.github.io/maypy","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mLetrone.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-23T16:05:04.000Z","updated_at":"2025-01-10T14:49:42.000Z","dependencies_parsed_at":"2024-12-09T23:29:18.158Z","dependency_job_id":"c288423b-dee8-4e4a-bbe0-ea610d3b7b32","html_url":"https://github.com/mLetrone/maypy","commit_stats":null,"previous_names":["mletrone/maybe","mletrone/maypy"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mLetrone%2Fmaypy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mLetrone%2Fmaypy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mLetrone%2Fmaypy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mLetrone%2Fmaypy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mLetrone","download_url":"https://codeload.github.com/mLetrone/maypy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235515437,"owners_count":19002481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","python3","typed","utils-library"],"created_at":"2025-01-11T03:31:50.119Z","updated_at":"2025-10-06T09:31:18.335Z","avatar_url":"https://github.com/mLetrone.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\" style=\"margin:40px;\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/MLetrone/maypy/master/docs/pages/assets/img/logo.png\" alt=\"Maypy logo\" style=\"margin-bottom: 20px; border-radius: 2rem\" width=\"300\"/\u003e\n\u003c!-- --8\u003c-- [start:overview-header] --\u003e\n\n  [![Language](https://img.shields.io/badge/Language-python≥3.9-3776ab?style=flat-square\u0026logo=Python)](https://www.python.org/)\n  ![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)\n  ![Style](https://img.shields.io/badge/Style-ruff-9a9a9a?style=flat-square)\n  ![Lint](https://img.shields.io/badge/Lint-ruff,%20mypy-brightgreen?style=flat-square)\n  [![Tests](https://github.com/MLetrone/maypy/actions/workflows/check.yml/badge.svg?branch=master)](https://github.com/MLetrone/maypy/actions/workflows/check.yml)\n\n\u003c!-- --8\u003c-- [end:overview-header] --\u003e\n\n---\n\nSource Code: [https://github.com/MLetrone/maypy](https://github.com/MLetrone/maypy)\n\ndocumentation: [https://mletrone.github.io/maypy](https://mletrone.github.io/maypy/)\n\n---\n\u003c/div\u003e\n\u003c!-- --8\u003c-- [start:overview-body] --\u003e\n\nMaypy is python implementation of the well known Java [Optional](https://docs.oracle.com/en%2Fjava%2Fjavase%2F11%2Fdocs%2Fapi%2F%2F/java.base/java/util/Optional.html) API.\nIt's designed to help you handle potential `None` values, reducing error from `NoneType`.\n\n## Features :\n- Brings functional programming\n- Easy to use\n- Fully typed and compatible with `mypy` !\n- Lightweight\n\n\u003c!-- --8\u003c-- [end:overview-body] --\u003e\n## installation\n\n```shell\npip install maypy\n```\n\nThat's all ! _Ready to use_\n\n## Usage\n\n### Description\n\n\u003c!-- --8\u003c-- [start:description] --\u003e\n\nIt's not rare to handle return from function that _maybe_ either a value or None.\nLike `.get` from a dictionary, results from api or ORM etc.\nWith no more `if value is None` with `MayPy`, encapsulate your value and do what you want to.\n\nMayPy brings `Maybe` a wrapper (container), it is either **empty** if the value passed was `None` or valuated,\nin this case it contains the value, and we can perform operation on it.\n\n\u003c!-- --8\u003c-- [end:description] --\u003e\n\n### Examples\n\nChecking value presence:\n\n```python\nfrom maypy import Maybe, Empty, maybe\n\nassert Empty().is_empty()\nassert maybe(None).is_empty()\nassert maybe(\"value\").is_present()\n```\nUsing chaining operation over wrapped value:\n```python\nfrom maypy import Maybe\nfrom typing import List, Optional\n\n\ndef convert_to_celsius(fahrenheit: float) -\u003e float:\n  return (fahrenheit - 32) * 5 / 9\n\n\nfahrenheit_temperatures: List[Optional[float]] = [32.45, None, 26.6, 100, 72, None, 10]\n\nfor temp in fahrenheit_temperatures:\n  Maybe.of(temp).map(convert_to_celsius).filter(lambda celsius: celsius \u003e 0)\n```\n\nDefining return from database result:\n\n````python\nfrom dataclasses import dataclass\nfrom enum import StrEnum, unique\n\nfrom maypy import Maybe, maybe\nfrom pydantic import BaseModel\nfrom sqlalchemy.orm import Session\n\n\n@unique\nclass Gender(StrEnum):\n  MALE = \"M\"\n  FEMALE = \"F\"\n  UNKNOWN = \"X\"\n\n\n@dataclass\nclass User:\n  id: str\n  email: str\n  gender: Gender\n\n\nclass UserEntity(BaseModel):\n  id: str\n  email: str\n  gender: str\n\n  class Config:\n    orm_mode = True\n\n\ndef get_user(db: Session, user_id: str) -\u003e Maybe[User]:\n  return maybe(db.query(UserEntity).filter(UserEntity.id == user_id).first()).map(to_domain)\n\n\ndef to_domain(user_dto: UserEntity) -\u003e User:\n  return User(\n    id=user_dto.id,\n    email=user_dto.email,\n    gender=Gender(user_dto.gender)\n  )\n\n\nuser = get_user(db, \"481efz4x1d\").or_else_raise(Exception(\"User id\u003c481efz4x1d\u003e not found\"))\n````","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmletrone%2Fmaypy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmletrone%2Fmaypy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmletrone%2Fmaypy/lists"}