Talk

Exploring Functional Options in Python

LanguageEnglish
Audience levelIntermediate
Elevator pitch

Designing APIs with many arguments is tough, and validating them can be even harder. Inspired by Golang’s functional options pattern, this talk explores how, and whether it’s a good idea, to implement this API design approach in Python, comparing it to alternatives like builder and chain patterns.

Abstract

Documenting lots of arguments well is hard. Validating each is even harder. Function arguments are not scalable past some point. Configuration structs are heavy, specially if every function expected it’s own config instance. Functional APIs solve this problem in their own awkward little way with a bit more code.

The first time I saw functional options in Golang, I didn’t fully understand why something as simple as configuring options (class or function args) looked so awkward. Then I read about the technique and realized that this solved a problem we have in every language, not just Golang.

Several years later, I found the chance to apply it when designing an API in Python and noticed no existing implementations! But was it a good idea?

This talk is about exploring a very interesting API option design from Golang’s Rob Pike in Python, and comparing it to other design patterns like builder & chain.

TagsAPIs, Best Practice, Algorithms and Data Structures
Participant

Rami Awar

Hello! I’m a full-stack engineer and AI consultant maintaining a couple of open source projects (DataLine, Pet).

In my free time, I really enjoy design, from complex software to music, art, and physical assemblies.

You can find me on Twitter talking about software and sharing my builds!