How to assign new index pattern to new space

How can I use Python code to create a new index pattern and space while importing an existing space dashboard and not assigning the pattern to it?