Package: python-compose
Python ComposePython Compose is a command line tool and library for spinning up many long-running python applications inisolated Python environments. Inspired byDocker Compose, Python Compose is meant to provide similar functionality without having to relying on Docker containers, networking etc.Currently, Python Compose supports the following environments:condamambapoetrypyenv-virtualenvvenvIn the future, we wish to support:pipenvpyenvInstallationUse the package managerpipto installpython-compose.pipinstallpython-composeCurrently, Python Compose supportsvenv,pyenv-virtualenvandcondaenvironments. Thepyenv-virtualenvandcondamanagers are not installed with Python Compose. To install them, follow instructions from thepyenv-virtualenvandcondadocumentation.ConceptsUnitAunitis an object which represents how to create, run and clean up a service for a specific type of Python environment handler. Examples can be found in thepython_compose/unitdirectory.YAML SpecificationPython Compile can currently only be instantiated from a YAML file with specification derived from the internalspec.pyPython file. A Python Compose YAML file expects a top-level key,unitswhich maps to a list ofunitsi.e. Python scripts to run. Each unit's environment is described by the keyunit_type. A unit will have different arguments. Some required, some are optional. Again, these definitions are inspec.pyAlternatives ComparisonPython Compose isn't the only tool in the world for this task. It happens to be a convenient one if you're working in a Python only environment and want to minimize external tools and dependencies. Below is a chart comparing Python Compose versus other solutions.ToolOperating SystemsVirtual NetworkingAbility to Run Non-Python ProgramsMultiple Python Version SupportNon-Python Dependencies RequiredPython ComposeLinux/MacOS❌With Conda orsubprocess✅❌Python MultiprocessingLinux/MacOS/Windows❌Withsubprocess❌❌Docker ComposeLinux/MacOS/Windows✅✅✅✅Systemd Unit FilesLinux❌✅✅✅BazelLinux/MacOS/Windows❌✅✅✅ExampleWe provide many examples of how to use Python Compose as both a library and as a command line tool in theexamplesdirectory. Below we provide what we will assume is the most Docker Compose-like use case, starting many backend services from a single config file.In a directory, create a Python script,httpd.pythat starts an HTTP service:importargparsefromhttp.serverimportBaseHTTPRequestHandler,HTTPServerif__name__=="__main__":parser=argparse.ArgumentParser()parser.add_argument("port",type=int)args=parser.parse_args()print(args)server_address=("",args.port)httpd=HTTPServer(server_address,BaseHTTPRequestHandler)httpd.serve_forever()Then, create a yaml file,config.yamlto start this backend service in multiple environments:units:-unit_type:"venv"name:"httpd_0"env_dir:"./.envs"script_path:"./httpd.py"script_args:["8080"]-unit_type:"venv"name:"httpd_1"env_dir:"./.envs"script_path:"./httpd.py"script_args:["8081"]-unit_type:"pyenv-virtualenv"name:"httpd_2"py_version:"3.10"script_path:"./httpd.py"script_args:["8082"]-unit_type:"conda"name:httpd_3script:["python3","../conda/httpd.py","8083"]To spin up all containers, runpython3-mpython-composeconfig.yamlTo exit, press<Ctrl-C>.ContributingPull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.Please make sure to update tests as appropriate.Setting up Your Development Environment.Developers should first install all needed development dependencies:pip3install-e'.[dev]'Then make all desired changesAdding a new UnitTo add a newunit, you will want to first add the unit topython_compose/unit. Then, add an example to the examples directory and finally updatespec.py.TestingTo test Python Compile, runpytestafter installation of all dev dependencies.LicenseMIT