| Name | bisex JSON |
| Version |
0.1.0
JSON |
| download |
| home_page | None |
| Summary | General‑purpose Python→TypeScript type generator |
| upload_time | 2025-09-14 17:34:50 |
| maintainer | None |
| docs_url | None |
| author | Hyv |
| requires_python | >=3.10 |
| license | MIT |
| keywords |
ast
codegen
dataclasses
enums
typescript
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
Bisex‑Base — Python → TypeScript type generator
================================================
General‑purpose utilities to generate TypeScript declarations from Python
types. Extracts static shapes from dataclasses/annotated classes, Enums,
TypedDicts and type aliases, and can also export TypeScript interfaces from
Python function signatures using type annotations.
Highlights
- Dataclasses / annotated classes → TS interfaces
- TypedDicts → TS interfaces
- Enums → TS enums (string/number literal members)
- Type aliases → TS `export type` (PEP 695 `type`, `typing.TypeAlias`, and common assignment aliases)
- Function signatures → TS interfaces (customizable return wrapper)
- No runtime imports of your modules needed for static types; uses AST
Quick start
-----------
```python
from pathlib import Path
from bysex import TsGen
gen = TsGen(
py_types=["path/to/types.py", "another/file.py"],
out_ts=Path("web/src/lib/types.generated.ts"),
return_wrapper=None, # or "() => Promise<{ret}>" for Eel‑style wrappers
)
# Optional: expose Python functions as a TS interface
@gen.interface("Backend")
def my_api(arg1: str, count: int) -> None: # type hints are used
...
gen.generate() # writes the file and returns the output Path
```
Design
------
- Static types are parsed via `ast` — no module import side effects.
- Function annotations are resolved with `typing.get_type_hints` (for forward refs),
falling back to `__annotations__`, then converted with `typing.get_origin/get_args` to produce TS types.
- Minimal, dependency‑free core (standard library only).
API
---
`TsGen(py_types, out_ts, return_wrapper=None)`
- `py_types`: `str | Path | Iterable[str | Path]` — .py files to scan for static types
- `out_ts`: `Path | str` — output .ts file
- `return_wrapper`: Optional[str] — format string where `{ret}` is replaced
with the return type. Example for Eel: `"() => Promise<{ret}>"`.
`interface(name: str)`
- Decorator that captures a function signature into an exported TS interface.
`produce_ts() -> str`
- Returns the generated TypeScript source (no disk writes).
`generate() -> Path`
- Writes to `out_ts` and returns the output path.
Limitations
-----------
- Complex typing constructs may fall back to `any`.
- Dataclass/typed class field defaults are ignored in TS generation.
- Enums with computed/complex values map to member names if values are not
string/number literals. Negative numbers are recognized as numeric literals.
- Type alias detection beyond PEP 695 and `typing.TypeAlias` uses a heuristic for
simple assignment aliases (e.g. `MyT = list[int]` or `MyT = int | str`). Plain
constant assignments like `VERSION = "1.0"` are intentionally ignored.
License
-------
This folder is part of the WuWa Mod Manager repository. Extract and publish as
you see fit. The package source lives under `bysex/` and is built via
`pyproject.toml` in this directory.
Raw data
{
"_id": null,
"home_page": null,
"name": "bisex",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "ast, codegen, dataclasses, enums, typescript",
"author": "Hyv",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/14/94/1499b51088af605470729d108e590c0e767eb42ac4b07d5c17f99766316d/bisex-0.1.0.tar.gz",
"platform": null,
"description": "Bisex\u2011Base \u2014 Python \u2192 TypeScript type generator\n================================================\n\nGeneral\u2011purpose utilities to generate TypeScript declarations from Python\ntypes. Extracts static shapes from dataclasses/annotated classes, Enums,\nTypedDicts and type aliases, and can also export TypeScript interfaces from\nPython function signatures using type annotations.\n\nHighlights\n- Dataclasses / annotated classes \u2192 TS interfaces\n- TypedDicts \u2192 TS interfaces\n- Enums \u2192 TS enums (string/number literal members)\n- Type aliases \u2192 TS `export type` (PEP 695 `type`, `typing.TypeAlias`, and common assignment aliases)\n- Function signatures \u2192 TS interfaces (customizable return wrapper)\n- No runtime imports of your modules needed for static types; uses AST\n\nQuick start\n-----------\n\n```python\nfrom pathlib import Path\nfrom bysex import TsGen\n\ngen = TsGen(\n py_types=[\"path/to/types.py\", \"another/file.py\"],\n out_ts=Path(\"web/src/lib/types.generated.ts\"),\n return_wrapper=None, # or \"() => Promise<{ret}>\" for Eel\u2011style wrappers\n)\n\n# Optional: expose Python functions as a TS interface\n@gen.interface(\"Backend\")\ndef my_api(arg1: str, count: int) -> None: # type hints are used\n ...\n\ngen.generate() # writes the file and returns the output Path\n```\n\nDesign\n------\n- Static types are parsed via `ast` \u2014 no module import side effects.\n- Function annotations are resolved with `typing.get_type_hints` (for forward refs),\n falling back to `__annotations__`, then converted with `typing.get_origin/get_args` to produce TS types.\n- Minimal, dependency\u2011free core (standard library only).\n\nAPI\n---\n\n`TsGen(py_types, out_ts, return_wrapper=None)`\n- `py_types`: `str | Path | Iterable[str | Path]` \u2014 .py files to scan for static types\n- `out_ts`: `Path | str` \u2014 output .ts file\n- `return_wrapper`: Optional[str] \u2014 format string where `{ret}` is replaced\n with the return type. Example for Eel: `\"() => Promise<{ret}>\"`.\n\n`interface(name: str)`\n- Decorator that captures a function signature into an exported TS interface.\n\n`produce_ts() -> str`\n- Returns the generated TypeScript source (no disk writes).\n\n`generate() -> Path`\n- Writes to `out_ts` and returns the output path.\n\nLimitations\n-----------\n- Complex typing constructs may fall back to `any`.\n- Dataclass/typed class field defaults are ignored in TS generation.\n- Enums with computed/complex values map to member names if values are not\n string/number literals. Negative numbers are recognized as numeric literals.\n- Type alias detection beyond PEP 695 and `typing.TypeAlias` uses a heuristic for\n simple assignment aliases (e.g. `MyT = list[int]` or `MyT = int | str`). Plain\n constant assignments like `VERSION = \"1.0\"` are intentionally ignored.\n\nLicense\n-------\nThis folder is part of the WuWa Mod Manager repository. Extract and publish as\nyou see fit. The package source lives under `bysex/` and is built via\n`pyproject.toml` in this directory.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "General\u2011purpose Python\u2192TypeScript type generator",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/hyvnova/bisex"
},
"split_keywords": [
"ast",
" codegen",
" dataclasses",
" enums",
" typescript"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "07bfb18a39f29f0c402acec2c3b41a0232a13d04fa97af0439fc927d7063a47d",
"md5": "16cea36289f97ac71a883874e0ead39f",
"sha256": "54f91a1a96a7a9e43055d38d35b6dc8122c943116fd11b5a49595d4e70bac13f"
},
"downloads": -1,
"filename": "bisex-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "16cea36289f97ac71a883874e0ead39f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 8252,
"upload_time": "2025-09-14T17:34:49",
"upload_time_iso_8601": "2025-09-14T17:34:49.875986Z",
"url": "https://files.pythonhosted.org/packages/07/bf/b18a39f29f0c402acec2c3b41a0232a13d04fa97af0439fc927d7063a47d/bisex-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "14941499b51088af605470729d108e590c0e767eb42ac4b07d5c17f99766316d",
"md5": "010ed803e1e22994b5f004a2de1169a8",
"sha256": "2cb747f0b4202407d3349008b76c819a9b5b6331f8be5546703ee7f297391d4d"
},
"downloads": -1,
"filename": "bisex-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "010ed803e1e22994b5f004a2de1169a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 10627,
"upload_time": "2025-09-14T17:34:50",
"upload_time_iso_8601": "2025-09-14T17:34:50.850170Z",
"url": "https://files.pythonhosted.org/packages/14/94/1499b51088af605470729d108e590c0e767eb42ac4b07d5c17f99766316d/bisex-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-14 17:34:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hyvnova",
"github_project": "bisex",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "bisex"
}