makefun

Dynamically create Python functions with a proper, correct signature for decorators and generators.

Library
PyPI
v1.16.0
135stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
47/100Fair
Development Activity0
Maintenance44
Community64
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture80
Code Quality84
Innovation82
Learning Curve78

makefun is a small, focused Python library for dynamically creating functions that expose a proper, accurate signature. Where Python’s built-in metaprogramming often produces wrappers with a generic *args/**kwargs signature, makefun lets you generate functions whose signature matches exactly what callers, IDEs, and introspection tools expect.

It is widely used as the engine behind advanced decorators, signature-preserving wrappers, and programmatically generated APIs. With helpers like create_function, wraps, and partial, makefun gives library authors precise control over generated callables while keeping runtime overhead low.

What You Get

  • create_function to build a callable from any signature specification and an implementation handler
  • A signature-preserving wraps decorator that improves on functools.wraps
  • partial that produces correctly-signed partially-applied functions
  • with_signature decorator for changing a function’s exposed signature
  • Support for positional-only, keyword-only, and variadic parameters across Python versions

Common Use Cases

  • Writing decorators that preserve the wrapped function’s exact signature
  • Generating API functions dynamically from schemas or configuration
  • Creating signature-accurate partial functions for cleaner public APIs
  • Building test fixtures and mocks that mimic real function signatures

Under The Hood

Architecture - makefun’s core lives in src/makefun and revolves around create_function, which parses a signature specification into an inspect.Signature, compiles a thin dispatcher function that exposes that signature, and routes all calls to a user-provided implementation handler that receives the bound arguments. Convenience decorators (wraps, with_signature, partial) are built on top of this primitive, and a compatibility layer smooths over differences in the inspect module across supported Python versions.

Tech Stack - Pure Python packaged with setuptools/pyproject, tested via nox with pytest, and checked with flake8 and coverage. It is essentially dependency-free at runtime, targeting a wide range of Python versions.

Code Quality - The project carries strong CI: JUnit test reports, coverage badges, and flake8 linting are all published. Tests are thorough and the codebase is compact, though development activity has slowed as the library is feature-complete for its narrow purpose.

API Design - The public API is small and discoverable: create_function for full control, plus decorators that read like their functools counterparts. Documentation on the project site includes worked examples, and the signature-first design makes intent explicit.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search