{"id":16393562,"url":"https://github.com/code-yeongyu/extended-type","last_synced_at":"2025-06-12T21:32:58.914Z","repository":{"id":189183330,"uuid":"680205652","full_name":"code-yeongyu/extended-type","owner":"code-yeongyu","description":"Boost Python's type hinting with `extended-types`: regex and range validations seamlessly.","archived":false,"fork":false,"pushed_at":"2023-08-18T18:52:03.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-04T04:13:30.148Z","etag":null,"topics":["pydantic","python","type","typehinting","typehints"],"latest_commit_sha":null,"homepage":"","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/code-yeongyu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-08-18T15:44:56.000Z","updated_at":"2023-08-23T07:00:40.000Z","dependencies_parsed_at":"2024-11-09T10:45:53.854Z","dependency_job_id":"e22ebd0b-a4c3-4239-afa0-9ab2881a236e","html_url":"https://github.com/code-yeongyu/extended-type","commit_stats":null,"previous_names":["code-yeongyu/extended-type"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-yeongyu%2Fextended-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-yeongyu%2Fextended-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-yeongyu%2Fextended-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-yeongyu%2Fextended-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-yeongyu","download_url":"https://codeload.github.com/code-yeongyu/extended-type/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240258771,"owners_count":19773055,"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":["pydantic","python","type","typehinting","typehints"],"created_at":"2024-10-11T04:53:37.857Z","updated_at":"2025-02-23T02:21:02.147Z","avatar_url":"https://github.com/code-yeongyu.png","language":"Python","readme":"# extended-type\n\nBoost Python's type hinting with extended-types: regex and range validations seamlessly.\n\nThis is an experimental collection of code snippets that work as intended, but it's not packaged for distribution yet.\n\n```python\nfrom dataclasses import dataclass\nfrom typing import Literal\n\nfrom extended_type import RangeInt, RegexStr\nfrom extended_type.type_extended import type_extended\n\n\n@type_extended\n@dataclass\nclass School:\n    school_code: RegexStr[Literal[\"^school.*$\"]]\n    school_name: str\n    age: RangeInt[Literal[10], Literal[20]]\n\nschool = School(school_code=\"school_1\", school_name=\"School 1\", age=15) # okay\nschool = School(school_code=\"sch\", school_name=\"School 1\", age=10) # ValueError: 'sch' does not match regex pattern '^school.*$'\nschool = School(school_code=\"school_1\", school_name=\"School 1\", age=21) # ValueError: 21 is not in range [10, 20]\nschool.school_code = \"sch\" # ValueError: 'sch' does not match regex pattern '^school.*$'\n```\n\n## Types Extended\n\n### str\n\n- `RegexStr`: Easily validate string attributes with regex patterns.\n\n```python\nfrom typing import Literal\nfrom extended_type import RegexStr, TypeExtended\nfrom dataclasses import dataclass\n\n@dataclass\nclass School(TypeExtended):\n    school_code: RegexStr[Literal[\"^school.*$\"]]\n    school_name: str\n\nschool = School(school_code=\"school_1\", school_name=\"School 1\")\nschool = School(school_code=\"scho\", school_name=\"School 1\") # ValueError: 'scho' does not match regex pattern '^school.*$'\n```\n\n- `PrefixStr`: Validate string attributes with a prefix.\n\n- `SuffixStr`: Validate string attributes with a suffix.\n\n- `ContainsStr`: Validate string attributes with a substring.\n\n- `EmailStr`: Validate string attributes with an email pattern.\n\n#### TBD\n\n- `NotContainsStr`: Validate string attributes with a not contains pattern.\n\n- `LengthStr`: Validate string attributes with a length pattern.\n\n- `NumericStr`: Validate string attributes with a numeric pattern.\n\n- `AlphabeticalStr`: Validate string attributes with an alphabetical pattern.\n\n- `AlphanumericStr`: Validate string attributes with an alphanumeric pattern.\n\n- `UrlStr`: Validate string attributes with a url pattern.\n\n- `PhoneStr`: Validate string attributes with a phone pattern.\n\n- `CreditCardStr`: Validate string attributes with a credit card pattern.\n\n- `LowercaseStr`: Validate string attributes with a lowercase pattern.\n\n- `UppercaseStr`: Validate string attributes with an uppercase pattern.\n\n### Numeric\n\n- `RangeInt`: Set boundaries for integer attributes.\n\n```python\nfrom typing import Literal\nfrom extended_type.range_int import RangeInt, TypeExtended\nfrom dataclasses import dataclass\n\n@dataclass\nclass Student(TypeExtended):\n    age: RangeInt[Literal[10], Literal[20]]\n\nstudent = Student(age=15)\nstudent = Student(age=9) # ValueError: 9 is not in range [10, 20]\nstudent = Student(age=21) # ValueError: 21 is not in range [10, 20]\n```\n\n- `RangeFloat`: Set boundaries for float attributes.\n\n```python\nfrom typing import Literal\nfrom extended_type.range_float import RangeFloat, TypeExtended\nfrom dataclasses import dataclass\n\n@dataclass\nclass Product(TypeExtended):\n    weight: RangeFloat[Literal['0.5'], Literal['5.0']]\n    height: RangeFloat[Literal[1], Literal[5]]\n\nproduct = Product(weight=2.5, height=2.5)\nproduct = Product(weight=0.4, height=3) # ValueError: 0.4 is not in range [0.5, 5.0]\nproduct = Product(weight=2.5, height=7) # ValueError: 7 is not in range [1.0, 5.0]\n```\n\n- `RangeDecimal`: Set boundaries for decimal attributes.\n\n```python\nfrom typing import Literal\nfrom extended_type.range_decimal import RangeDecimal, TypeExtended\nfrom dataclasses import dataclass\n\n@dataclass\nclass Transaction(TypeExtended):\n    amount: RangeDecimal[Literal[\"0.01\"], Literal[\"1000.00\"]]\n    amount2: RangeDecimal[Literal[1], Literal[10]]\n\ntransaction = Transaction(amount=Decimal(\"150.75\"), amount2=Decimal(\"5.0\"))\ntransaction = Transaction(amount=Decimal(\"0.005\"), amount2=Decimal(\"5.0\")) # ValueError: 0.005 is not in range [0.01, 1000.00]\ntransaction = Transaction(amount=Decimal(\"150.75\"), amount2=Decimal(\"15\")) # ValueError: 15 is not in range [1, 10]\n```\n\n#### TBD\n\n- `Positive*`: Validate integer | float | Decimal attributes with a positive pattern.\n\n- `Negative*`: Validate integer | float | Decimal attributes with a negative pattern.\n\n- `Odd*`: Validate integer | float | Decimal attributes with an odd pattern.\n\n- `Even*`: Validate integer | float | Decimal attributes with an even pattern.\n\n- `Divisible*`: Validate integer | float | Decimal attributes with a divisible pattern.\n\n### ETC\n\n... More types will be added soon.\nYour suggestions are welcome! 🎉\n\n## To Do\n\n- [ ] Add Tests\n- [ ] Add CI/CD\n- [ ] Add PyPi package\n- [ ] Add more types (Suggestions are welcome! 🎉)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-yeongyu%2Fextended-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-yeongyu%2Fextended-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-yeongyu%2Fextended-type/lists"}