> This page is for SDKs, version Current (default).
> For other versions, use one of these documentation indexes:
> - Current (default): https://buildwithfern.com/learn/sdks/current/llms.txt
> - Legacy: https://buildwithfern.com/learn/sdks/legacy/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

# Adding custom code

> Learn how to add custom logic, methods, and dependencies to your Python SDK. Extend Fern-generated clients with custom code.

> **Enterprise feature**
>
> This feature is available only for the [Enterprise plan](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com).

This page covers how to add custom logic, methods, and dependencies to your Python SDK.

## Adding custom logic

To get started adding custom code:

> **Note**
>
> These steps cover adding a new custom file to the SDK. To preserve line-level edits to a generated file, use [Replay](/learn/sdks/overview/custom-code#replay) instead.

### Create a new file and add your custom logic

**`src/<package>/helper.py`**

```python title="src/<package>/helper.py"
def my_helper() -> None:
  print("Hello World!")
```

### Add your file to `.fernignore`

**`.fernignore`**

```yaml {3} title=".fernignore"
# Specify files that shouldn't be modified by Fern

src/<package>/helper.py
```

### Consume the helper

Now your users can consume the helper function by importing it from the SDK.

```python
from package.helper import my_helper

my_helper()
```

## Adding custom SDK methods

Fern also allows you to add custom methods to the SDK itself (e.g.
`client.my_method()` ) by inheriting the Fern generated client and then
extending it.

> **Note**
>
> See an example from ElevenLabs using this process in their [Python SDK](https://github.com/elevenlabs/elevenlabs-python/blob/main/src/elevenlabs/client.py).

### Update `sdk-config.yml` configuration

Name your Fern-generated client something like `BaseClient` to reflect
that this client will be extended. Configure the generator to output the
client in a file called `base_client.py`.

**`sdk-config.yml`**

```yaml {3-10} title="sdk-config.yml"
targets:
  - language: python
    generation:
      naming:
        clientName: BaseClient           # The name of the generated client you will extend
        exportedClientName: YourClient   # The name of the class you will be creating that extends the generated client
      client:
        fileName: base_client.py         # The name of the file the generated client will live in
        exportedFileName: client.py
```

### Generate the SDK

Trigger SDK generation by running `fern generate`:

```bash
fern generate --group sdk
```

### Import and extend the generated client

First, import the Fern generated base clients from `.base_client.py` and extend them to create your custom clients. Then, add whatever methods you want.

**`src/<package>/client.py`**

```python title="src/<package>/client.py"
  from .base_client import BaseClient // import generated client
  
  class YourClient(BaseClient): // extend generated client
      def my_helper(self) -> None:
          print("Hello World!")
          def my_helper(self) -> None:
              print("Hello World")
```

> **Note**
>
> See an example [client.py](https://github.com/elevenlabs/elevenlabs-python/blob/main/src/elevenlabs/client.py) from ElevenLabs.

### Update `.fernignore`

Add the `client.py` to `.fernignore`.

**`.fernignore`**

```diff title=".fernignore"
+ src/<package>/client.py
```

> **Note**
>
> See an example [.fernignore](https://github.com/elevenlabs/elevenlabs-python/blob/main/.fernignore) from ElevenLabs.

### Consume the method

Now your users can consume the helper function by importing it from the SDK.

```python
client.my_helper()
```

## Adding custom dependencies

To add packages that your custom code requires, list them in the target's `package.extraDependencies` and `package.extraDevDependencies` in `sdk-config.yml`.

**`sdk-config.yml`**

```yaml {4-10} title="sdk-config.yml"
targets:
  - language: python
    package:
      extraDependencies:
        - name: numpy
          version: "1.2.0"
      extraDevDependencies:
        - name: requests_mock
          version: "1.12.1"
```