ghostos-container

raw JSON →
0.2.7 verified Sat May 09 auth: no python

An IoC container library for Interface-oriented programming in Python, part of the GhostOS ecosystem. Currently version 0.2.7, requires Python >=3.10. Release cadence is irregular with recent dev releases for 0.4.0.

pip install ghostos-container
error ModuleNotFoundError: No module named 'ghostos_container'
cause Incorrect import path: using package name with hyphen instead of underscore.
fix
Change import to 'from ghostos.container import ...'
error ImportError: cannot import name 'Container' from 'ghostos.container'
cause Typo or incorrect symbol name. The symbol may be misspelled or not yet imported.
fix
Ensure you are using the correct symbol: 'Container', 'Provider', etc. Check the documentation.
error AttributeError: 'Container' object has no attribute 'register'
cause Using the wrong method. The container might use 'set' or 'bind' instead.
fix
Use container.set(key, value) for simple registration, or implement Provider.
gotcha The package name on PyPI uses a hyphen (ghostos-container) but the Python module uses an underscore (ghostos.container). This often causes confusion with imports.
fix Use 'from ghostos.container import ...' not 'from ghostos_container import ...'.
gotcha The library is part of the larger GhostOS project and may have dependencies on other ghostos packages not explicitly listed. Ensure you install the required extras (e.g., ghostos[realtime]) if you need full functionality.
fix Check the GhostOS documentation for additional packages. For basic container usage, ghostos-container is standalone.
deprecated The GitHub repository shows v0.4.0-dev1 which deprecates MossAgent in favor of MossGhost. This may affect future releases of ghostos-container if it re-exports those symbols.
fix Migrate from MossAgent to MossGhost when upgrading to 0.4.0+.

Basic usage of ghostos-container: define a Provider, register it, and retrieve a value.

from ghostos.container import Container, Provider

# Define a simple provider
class GreetingProvider(Provider):
    def register(self, container: Container):
        container.set('greeting', 'Hello, world!')

# Create container and use it
container = Container()
container.register(GreetingProvider())
print(container.get('greeting'))