Lesson 09 of 55
15 mins readPython Interfaces and Contracts
In Plain English
Interfaces define contracts within your code and contracts with code outside your project. Learn how to write interface definitions, methods, and nested structures.
Core Rules to Remember

Structural Contracts: Defines property and method requirements for objects and classes.

Extensibility: Supports declaration merging and multi-interface inheritance.
Live Interactive Example
Hit Run Code to see it liveDefining and Implementing Interfaces
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Output Console
Click "Run Code" to view the rendered output.
How it works: The object adheres strictly to the shape and method signatures mandated by DatabaseClient.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Define an AuthProvider Contract
Create an interface AuthProvider with name (string), isAvailable (boolean), and authenticate(token: string) returning boolean.
Implement an auth object satisfying AuthProvider and print its name and an authentication call.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.