Adding custom code
Fern-generated SDKs are designed to be extended with custom code. Your custom code can add additional functionality to the SDK and live in harmony with the generated code.
This page explains how to configure custom logic using a
.fernignore
file, create custom SDK methods, and add additional dependencies to your SDK.
Adding custom logic
If you want your SDK to do more than just make basic API calls (like combining
multiple calls, processing data, adding utilities), you can use .fernignore
to
protect your custom code from being overwritten during regeneration.
Simply add your custom files to the SDK repository and list them out in .fernignore
. Fern
won’t override any files that you add in .fernignore
.
To get started adding custom code:
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.
See an example from ElevenLabs using this process in their Python SDK.
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
.
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.
See an example client.py from ElevenLabs.
Update .fernignore
Add the client.py
to .fernignore
.
See an example .fernignore from ElevenLabs.
Adding custom dependencies
To add packages that your custom code requires, update your generators.yml
.