Skip to main content

myts

PyPI - Version PyPI - Python Version GitHub License GitHub Actions Workflow Status

In beta

Road to ready:

  • Better test coverage, 80% baseline
  • Support for generics, enums with auto, most MyPy typing.

Converts MyPy types to TS types. Uses MyPy's internal api to gather type info. Including your pydantic project if its MyPy friendly.

Call as a cli, optionally directory watchable. Or import and invoke directly from your Python code.

Installation

pip

pip install myts

uv

uv add myts 

poetry

poetry add myts

Usage

In your code

Myts looks for any classes that inherit from MytsType to start building its dependency graph. These by default will be included in the output TS.

Alternatively you can use the myts_export decorator on Enums and TypedDicts and classes that you would like to have exported without needing to be referenced by a MytsType class.

from enum import IntEnum
from myts import MytsType, myts_export

@myts_export
class Fruit(IntEnum): # Will be in the TS output
	apple = 0
	orange = 1
	banana = 2

class Vegetable(IntEnum): # Will not be, because it is not referenced ever and is not decorated with myts_export
	carrot = 0
	celery = 1
	lettuce = 2

class Drink(IntEnum): # Will be in the output, reference by a MytsType below
	water = 0
	milk = 1
	soda = 2

class BeveragePreference(MytsType): # Will export and will also export the Drink enum
	drink: Drink
	person: Person

CLI

To see all cli options run

myts -h

Optionally a config file can be used. By default myts will attempt to find a myts.toml in the specified root. Alternatively a config file can be supplied through the -c or --config argument to the cli.

You can also specify these options under a [tool.myts] section in your pyproject.toml found at the --root path.

Note: that arguments to the cli will override config settings found in the config.

The resolution of options is: (lowest → highest priority)

  1. pyproject [tool.myts]
  2. myts.toml
  3. command line arguments

Meaning an option defined in [tool.myts] can and will be overwritten by the same option if provided to myts.toml or the command line.

myts.toml or [tool.myts] is a flat toml that can optionally supply any or none of the following:

root = "/some/path" # If specifying root in the config make sure it is an absolute path
output = "./out/" # When output is relative, it is relative to root
group = "module" # "module" or "single"
preserve_structure = true # When group is "module" this will create folders matching the py structure
dry_run = false
#output_file_name = "out.ts" # When using group = "single" this will be the name of the output file
#trim_root = "myapp.has.a.long.root.path" # Optionally provide a python formatted module path to trim from all output

Simplest example

To generate the .ts files.

cd <myprojectroot>
myts --output your/output/dir/

A more complex example

Uses trim-root to remove a common py module path from the output.

Uses watch to automatically update generated ts when the py changes.

cd <myprojectroot>
myts --output your/output/dir/ -w

Py

import pathlib
import myts
from myts.cli.main import extract_ts

config = myts.MytsConfiguration(
	root=pathlib.Path('someprojdir'), # defaults to os.cwd()
	output=pathlib.Path('someoutputdir'),
	group='module', # 'single' or 'module' - single will output a single .ts file, 'module' will output files matching the `py` files they come from
	preserve_structure=True, # No effect if group == 'single', otherwise determines output structure. If true folders will be created to match py paths
	dry_run=False, # If true, just prints the paths of output files that would be written
	output_file_name='types.ts', # Only used if group == 'single', determines the name of the single file generated
	trim_root="myapp.some.path" # When preserving structure, use this to trim a common root 
)

extract_ts(config)

Roadmap

  • Export to multiple files, flat folder or matching py module structure
  • Support generics
  • Watch for py changes and auto generate ts
  • Config options for
    • Variable and type naming options (camelCase, PascalCase, snake_case)
    • Interface vs type output
  • Special support for pydantics built-ins (might build a plugin architecture to support)

Exporter configuration

Currently, myts only has 1 built-in exporter for ts. However it has been designed to easily support multiple exporters in the future, including the potential for custom exporters(actually achievable today, just without a "formal" plugin architecture).

The TS exporter can be configured by adding a [exporter.ts] section to your myts config:

[exporter.ts]
enum_output_format = "typed_const_map" # or "std_enum" to use TS enums. Default is typed_const_map for DX
typeddict_output_format = "interface" # or "type". Default interface to support inheritance
class_output_format = "interface" # or "type". Default interface to support inheritance
use_declare = true # default true, for any `type` declarations will precede with 'declare' if true
indent = "tabs" # default tabs, because they're superior, "spaces" is an option, currently the number of spaces is 4 and not yet configurable

Example of functionality

Python (Mypy)

from myts import MytsType, myts_export
from pydantic import BaseModel


class APIModel(BaseModel, MytsType):
	"""
		All pydantic models that extend from this will be picked up by Myts
	"""
	...


class MyPydanticModel(APIModel): # Myts will grab this
	name: str


class Fruits(Enum):
	APPLE = auto()
	BANANA = auto()
	GRAPES = auto()

class MyGenericClass[T: str | int]:
	my_var: T
	fruits: list[Fruits]

Output (Typescript)

export interface MyPedanticModel {
	name: string;
}

export const Fruits = {
	APPLE: 1,
	BANANA: 2,
	GRAPES: 3,
} as const;
export type Fruits = typeof Fruits[keyof typeof Fruits];

export interface MyGenericClass<T extends string | number> {
	myVar: T;
	fruits: Array<Fruits>;
}

Metadata

Release files for myts 0.3.12

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

Source distribution (sdist)

Source distribution for myts 0.3.12
File Size Uploaded Provenance Actions
myts-0.3.12.tar.gz 17.5 kB With provenance Details for myts-0.3.12.tar.gz

Built distribution (wheel)

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

Total release size: 41.2 kB

Release files / myts-0.3.12.tar.gz

Download URL myts-0.3.12.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9ec24bee53f7c345280c4fbded2bddd73f8bda15039f93bed0647344524883d7
BLAKE2b-256 checksum
How to use checksums
a2f4e53475eb7608240e03a8a0d687929ae4155c60f030a0532d3af2a8434e3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Release files / myts-0.3.12-py3-none-any.whl

Download URL myts-0.3.12-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bf01e45232bdeeff08dd5cf667ad09803eeacba96303840c8bc3ae13d208751
BLAKE2b-256 checksum
How to use checksums
1ca76c2b9ab5fe60a8c5f5e2b8dd36c3a65305a69436d4ac0bc3c78115589a5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Security for myts 0.3.12

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for myts-0.3.12.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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