# Adding custom code

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

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

<Info>
  Before getting started, 

  [read about how Fern SDKs use custom code and learn about the `.fernignore` file](/sdks/overview/custom-code)

  .
</Info>

## Adding custom logic

To get started adding custom code:

<Steps>
  ### Create a new file and add your custom logic

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

  ### Add your file to `.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()
  ```
</Steps>

## 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).
</Note>

<Steps>
  ### Update `generators.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`.

  ```yaml {4-8} title="generators.yml"
  - name: fernapi/fern-python-sdk
    version: "..."
    config:
      client:
        class_name: BaseClient        # The name of the generated client you will extend
        filename: base_client.py      # The name of the file the generated client will live in
        exported_class_name: YourClient   # The name of the class you will be creating that extends the generated client
        exported_filename: 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.

  ```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.
  </Note>

  ### Update `.fernignore`

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

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

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

  ### Consume the method

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

  ```python
  client.my_helper()
  ```
</Steps>

## Adding custom dependencies

<Warning title="Pro and Enterprise feature">
  This feature is available only for the [Pro and Enterprise plans](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com).
</Warning>

To add packages that your custom code requires, update your `generators.yml`.

```yaml {4-7} title="generators.yml"
- name: fernapi/fern-python-sdk
  version: "..."
  config:
    extra_dependencies:
      numpy: '1.2.0'
    extra_dev_dependencies:
      requests_mock: '1.12.1'
```