# Use custom Python modules from a Git repository

In some cases, you will want to use your own and already existing Python code. 

In order to import your custom Python modules and use it in a [Custom action](/dpe/actions/custom/index), you may refer to an external Git repository that will be pulled before each build of your job.

Here are the steps in order to use an external Git repository as a Python module:

1. Adapt your module so that its compatible with `pip install` 
  * see [setuptools documentation](https://packaging.python.org/guides/distributing-packages-using-setuptools/)
2. Your Python module must be hosted on an accessible host, if repository is private, you need to get an `access token`. 
For instance, in [GitHub](https://github.com), you must generate a **personal access token** 
(Other providers may have similar procedures)
  * [how to set tokens](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token)
  * [set your personal token in GitHub](https://github.com/settings/tokens)
3. Check that downloading of the package works well with your token 
  * Zip Archive: `https://<access_token>@github.com/<myorg>/<myProject>/archive/<ref>.zip`
  * Git: `git+https://<access_token>@github.com/<myorg>/<myProject>.git`
  * Git with a tag name or commit hash: `git+https://<access_token>@github.com/<myorg>/<myProject>.git@<tag>`
  * Git with automatic latest release: `git+https://<access_token>@github.com/<myorg>/<myProject>.git@latest`
4. Check that `pip install` works with your URL on your local computer 
```bash
pip install <URL>
```
5. In your project, in a custom action, add the dependencies in the **Advanced Mode** in `forepaas.json`: 
  * with a HTTPS Zip archive 
```json
      {
        "dependencies": {
          "python": {
            "https://<access_token>@github.com/<myorg>/<myProject>/archive/<ref>.zip": null
          }
        }
      }
```
  * with a Git+HTTPS repository
```json
      {
        "dependencies": {
          "python": {
            "git+https://<access_token>@github.com/<myorg>/<myProject>.git": null
          }
        }
      }
```
  * with a Git+HTTPS repository, including a `tag` name or a `commit hash`
```json
      {
        "dependencies": {
          "python": {
            "git+https://<access_token>@github.com/<myorg>/<myProject>.git@<tag>": null
          }
        }
      }
```
  * with a Git+HTTPS repository, automatically using the latest release
```json
      {
        "dependencies": {
          "python": {
            "git+https://<access_token>@github.com/<myorg>/<myProject>.git@latest": null
          }
        }
      }
```

?> **Auto-resolving the latest release:** Using `@latest` at the end of a `git+` dependency URL instructs the platform to automatically fetch and substitute the most recent release tag before installing. This removes the need to update each action's dependency manually when a new version of your module is published — click **Force Build** to pick up the new release. Note that the latest release is not detected automatically at runtime — a manual **Force Build** is always required.

!> Pinning a specific `tag` or `commit hash` gives you precise control over which version is used at execution time and is recommended for production workloads.


6. In your custom action python code, you can now import and use it!
```python
import mypackage
```





