> ## Documentation Index
> Fetch the complete documentation index at: https://codegeninc-codegen-bot-sdk-docs-2-0.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Language Support

Codegen provides first-class support for both Python and TypeScript codebases. The language is automatically inferred when you initialize a codebase.

## Language Detection

When you create a new `Codebase` instance, Codegen automatically detects the programming language:

```python
from codegen import Codebase

# Automatically detects Python or TypeScript
codebase = Codebase("./")

# View language with `codebase.language`
print(codebase.language)  # "python" or "typescript"
```

<Tip>
  Learn more about codebase initialization options in [Parsing
  Codebases](/building-with-codegen/parsing-codebases).
</Tip>

## Type System

Codegen uses specialized types for each language. These are defined as type aliases:

```python
# Python codebases use PyCodebaseType
PyCodebaseType = Codebase[
    PyFile, Directory, PySymbol, PyClass, PyFunction,
    PyImport, PyAssignment, Interface, TypeAlias,
    PyParameter, PyCodeBlock
]

# TypeScript codebases use TSCodebaseType
TSCodebaseType = Codebase[
    TSFile, Directory, TSSymbol, TSClass, TSFunction,
    TSImport, TSAssignment, TSInterface, TSTypeAlias,
    TSParameter, TSCodeBlock
]
```

Every code element has both a Python and TypeScript implementation that inherits from a common base class. For example:

* [Function](/api-reference/core/Function)
  * [PyFunction](/api-reference/python/PyFunction)
  * [TSFunction](/api-reference/typescript/TSFunction)
* [Class](/api-reference/core/Class)
  * [PyClass](/api-reference/python/PyClass)
  * [TSClass](/api-reference/typescript/TSClass)
* [Import](/api-reference/core/Import)
  * [PyImport](/api-reference/python/PyImport)
  * [TSImport](/api-reference/typescript/TSImport)

...

```python
# Base class (core/function.py)
class Function:
    """Abstract representation of a Function."""
    pass

# Python implementation (python/function.py)
class PyFunction(Function):
    """Extends Function for Python codebases."""
    pass

# TypeScript implementation (typescript/function.py)
class TSFunction(Function):
    """Extends Function for TypeScript codebases."""
    pass
```

This inheritance pattern means that most Codegen programs can work with either Python or TypeScript without modification, since they share the same API structure.

```python
# Works for both Python and TypeScript
for function in codebase.functions:
    print(f"Function: {function.name}")
    print(f"Parameters: {[p.name for p in function.parameters]}")
    print(f"Return type: {function.return_type}")
```

## TypeScript-Specific Features

Some features are only available in TypeScript codebases:

* **Types and Interfaces**: TypeScript's rich type system ([TSTypeAlias](/api-reference/typescript/TSTypeAlias), [TSInterface](/api-reference/typescript/TSInterface))
* **Exports**: Module exports and re-exports ([TSExport](/api-reference/typescript/TSExport))
* **JSX/TSX**: React component handling (see [React and JSX](/building-with-codegen/react-and-jsx))

Example of TypeScript-specific features:

```python
# Only works with TypeScript codebases
if isinstance(codebase, TSCodebaseType):
    # Work with TypeScript interfaces
    for interface in codebase.interfaces:
        print(f"Interface: {interface.name}")
        print(f"Extends: {[i.name for i in interface.parent_interfaces]}")

    # Work with type aliases
    for type_alias in codebase.type_aliases:
        print(f"Type alias: {type_alias.name}")
```
