Welcome to the apywire user guide! This section provides comprehensive documentation on all features and capabilities of apywire.
Learn the fundamentals of using apywire, including creating wiring containers, defining specs, using the Accessor pattern, and understanding caching behavior.
Load specs from YAML, TOML, JSON, or INI files. Mix configuration files with environment variables and implement environment-based configs.
Discover how to use apywire in asynchronous contexts with await wired.aio.name() for async object access.
Understand thread-safe instantiation, optimistic locking mechanisms, and configuration options for multi-threaded applications.
Learn how to generate standalone Python code from your wiring specs using WiringCompiler for production deployment and performance optimization.
Quickly scaffold wiring specs from class constructor signatures using Generator.
Explore advanced capabilities including factory methods, positional arguments, complex nested dependencies, error handling, and best practices.
apywire is designed around a few core principles:
- Lazy Loading: Objects are instantiated only when accessed, improving startup performance
- Dependency Injection: Use placeholder syntax to express dependencies between objects
- Flexibility: Support for keyword arguments, positional arguments, factory methods, and constants
- Type Safety: Strict mypy typing throughout the library
- Performance: Optional code generation via Cython for production deployments
Looking for something specific?
- Getting started? → Basic Usage
- Need async? → Async Support
- Multi-threaded app? → Thread Safety
- Production deployment? → Compilation
- Complex use cases? → Advanced Features
- Scaffold specs quickly? → Spec Generation
- Define your wiring spec with dependencies
- Create a
Wiringcontainer - Access objects via the Accessor pattern
- Use
thread_safe=Falsefor single-threaded development
- Test your wiring configuration thoroughly
- Use
WiringCompilerto generate standalone code - Enable
thread_safe=Trueif deploying multi-threaded - Optionally compile with Cython for maximum performance
- Define test-specific specs with mock objects
- Use placeholder references to inject test doubles
- Leverage lazy loading to avoid unnecessary instantiation
- Test circular dependency behavior — see Circular dependencies
- Keep specs simple: Break complex wiring into smaller, focused specs
- Use placeholders: Express dependencies explicitly with
{name}syntax - Validate early: Access all wired objects in tests to catch configuration errors
- Document dependencies: Comment complex dependency chains in your specs
- Consider thread safety: Enable
thread_safe=Trueonly when needed (has overhead) - Compile for production: Use
WiringCompilerto generate optimized code
Start with Basic Usage to learn the fundamentals, then explore the other guides based on your specific needs.