Using the latest version?
JFrog Platform User Guide


Skip to end of metadata
Go to start of metadata

Overview

Artifactory fully supportsPyPIrepositories providing:

  1. The ability to provision PyPI packages from Artifactory to thepipcommand line tool from all repository types.
  2. Calculation of Metadata for PyPI packages hosted in Artifactory's local repositories.
  3. Access to remote PyPI repositories (such ashttps://pypi.org/) throughRemote Repositorieswhich provide proxy and caching functionality.
  4. The ability to access multiple PyPI repositories from a single URL by aggregating them under aVirtual Repository.
  5. Compatibility with thesetuptoolsand its predecessordistutilslibraries for uploading PyPI packages.


Running on Windows

To use Artifactory PyPI repositories on Windows, make sure to set the required environment variables for Python and Pip.

Note that on Windows platforms,%HOME%\pip\pip.inireplaces thepip.conffile described in the sections below and should be reachable through your HOME path.


Configuration

当地Repositories

To create a new PyPI local repository, in theNew Local Repositoryscreen, set thePackage TypetoPyPI.

New local PyPI repository

Page Contents

Remote Repositories

Requires Artifactory 5.8.10, 5.9.7, 5.10.4 and above or 6.x

Due to severalchanges introduced to PyPIin April 2018, to proxyhttps://pypi.org/using a remote repository, you need to work with Artifactory 5.8.10, 5.9.7, 5.10.4 or above (including 6.x).

ARemote Repositorydefined in Artifactory serves as a caching proxy for a registry managed at a remote URL such ashttps://pypi.python.org/.

Artifacts (such as .whl files) requested from a remote repository are cached on demand. You can remove downloaded artifacts from the remote repository cache, however you can not manually deploy artifacts to a remote PyPI repository.

To create a repository to proxy a remote PyPI repository follow the steps below:

  1. In theAdminmodule underRepositories | Remote,select "New"
  2. Set thePackage TypetoPyPIand enter theRepository Keyvalue.

  3. 取决于是否成URL和注册表的URL设置r you are proxying the public external PyPI repository, or a PyPI repository hosted on another Artifactory server.
    For a public, external PyPI repository:Change theURLfield tohttps://files.pythonhosted.org/, and set theRegistry URLfield tohttps://pypi.org/as shown below:



    For a PyPI repository hosted on another Artifactory instance:Set the remote repository's PyPI API URL in both theURLfield and theRegistry URLfield. For example, to proxy a PyPI repository called "python-project" hosted by an Artifactory instance athttps://my.remote.artifactory/artifactory/, you would set both theURLfield and theRegistry URLtohttps://my.remote.artifactory/artifactory/api/pypi/python-projectas shown below:

    PyPI Smart Remote repository


    PyPI remote repository URL

    You should not include "/pypi" or "/simple" in the the PyPI remote repository URL.These suffixes are added by Artifactory when accessing the remote repository.

    If you use a custom PyPI remote repository, you need to make sure it has a simple index(directory listing style)accessible by/simple.

    Registry URL field is version specific

    TheRegistry URLfield is only available in Artifactory 5.10.3 and above.

    For patch versions provided for Artifactory 5.8.9 and above and Artifactory 5.9.5 and above,to support the new PyPI structure, the only change you need to make is to set the URL field tohttps://pypi.org. Thehttps://files.pythonhosted.orgis automatically extracted from a system property,artifactory.pypi.default.download.urlwhich is set to this value by default.

  4. Click "Save & Finish"

    Remote Artifactory

    If the remote repository is also managed by an Artifactory server, then you need to point to its PyPI API URL in bothURLfield andRegistry URLfield. For examplehttp://my.remote.artifactory/artifactory/api/pypi/python-project

Virtual Repositories

A Virtual Repository defined in Artifactory aggregates packages from both local and remote repositories.
This allows you to access both locally hosted PyPI packages and remote proxied PyPI repositories from a single URL defined for the virtual repository.
To define a virtual PyPI repository, createvirtual repository, set itsPackage Typeto be PyPI, select the underlying local and remote PyPI repositories to include in theBasicsettingstab, click "Save & Finish".



Resolving from Artifactory Using PIP

To install thepipcommand line tool refer topip documentation pages. We recommend usingvirtualenvto separate your environment when installing PIP.

To display code snippets you can use to configurepipandsetup.pyto use your PyPI repository, select the repository and then clickSet Me Up.


Specifying the Repository on the Command Line

Index URL

When accessing a PyPI repository through Artifactory, the repository URL must be prefixed withapi/pypiin the path. This applies to allpipcommands anddistutilsURLs includingpip install.

When usingpipto resolve PyPI packages it must point to/api/pypi//simple.

For example, if you are using Artifactory standalone or as a local service, you would access your PyPI repositories using the following URL:

http://localhost:8081/artifactory/api/pypi//simple

Or, if you are using Artifactory SaaS, the URL would be:

https://.jfrog.io//api/pypi//simple


Once pip is installed, it can be used to specify the URL of the repository from which to resolve:

Installing with full repository URL
$ pip install frog-bar -i http://localhost:8081/artifactory/api/pypi/pypi-local/simple

Using Credentials

Due to it's design, pip does not support reading credentials from a file. Credentials can be supplied as part of the URL, for examplehttp://:@localhost:8081/artifactory/api/pypi/pypi-local/simple.The password can be omitted (with the preceding colon), and in this case, the user will be prompted to enter credentials interactively.

Using a Configuration File

Aliases for different repositories can be specified through a pip configuration file,~/.pip/pip.conf. The file contains configuration parameters per repository, for example:

~/.pip/pip.conf
[global] index-url = http://user:password@localhost:8081/artifactory/api/pypi/pypi-virtual/simple

For more information, please refer toPIP User Guide.

Using a Requirements File

A requirements file contains a list of packages to install. Usually these are dependencies for the current package. It can be created manually or using thepip freezecommand. The index URL can be specified in the first line of the file, For example:

requirements.txt
--index-url http://localhost:8081/artifactory/api/pypi/pypi-local/simple PyYAML==3.11 argparse==1.2.1 frog-bar==0.2 frog-fu==0.2a nltk==2.0.4 wsgiref==0.1.2



Publishing to Artifactory

Using distutils or setuptools

setuptools vs. distutils and python versions

Artifactory is agnostic to whether you usesetuptoolsordistutils, and also to the version or implementation of Python your project uses.

The following instruction were written for Python 2.7 andsetuptoolsin mind. Usingdifferent version of Python, ordifferent tools suchzest, distutilsand others may require minor modification to the instructions below.

Uploading to Artifactory using asetup.pyscript is supported in a similar way to uploading to PyPI. First, you need to add Artifactory as an index server for your user.

For instructions on usingsetuptoolsto package Python projects and create asetup.pyscript, please refer to thesetuptools documentationandthis tutorial project.

Create the $HOME/.pypirc File

To upload to Artifactory, an entry for each repository needs to be made in$HOME/.pypircas follows:

[distutils] index-servers = local pypi [pypi] repository: https://pypi.org/pypi username: mrBagthrope password: notToBeSeen [local] repository: http://localhost:8081/artifactory/api/pypi/pypi-local username: admin password: password

Notice that the URL does not end with/simple.

The HOME environment variable

setuptoolsrequires that the.pypircfile be found under$HOME/.pypirc,using theHOMEenvironment variable.

On unix-like systems this is usually set by your system to/home/yourusername/but in certain environments such as build servers you will have to set it manually.

On Windows it must be set manually.

Uploading

After creating a.pypircfile and asetup.pyscript at the root of your project, you can upload your egg (tar.gz) packages as follows:

~/python_project $ python setup.py sdist upload -r local

If you are using wheel (whl) you can upload your packaged as follows:

~/python_project $ python setup.py bdist_wheel upload -r local

Or if you wish to use both egg (tar.gz) and wheel (whl), you can upload them as follows:

~/python_project $ python setup.py sdist bdist_wheel upload -r local

Wherelocalis the name of the section in your.pypircfile that points to your Artifactory PyPI repository.

Default upload

By default, bothsetuptoolsanddistutilswill upload tohttps://pypi.org/pypiif no repository is specified.

The 'register' command should be omitted

When uploading directly topypi.org,the documentation states that your package must first be registeredby callingpython setup.pyregister.

When uploading to Artifactory this is neither required nor supported andshould be omitted.

Publishing Manually Using the Web UI or REST

PyPI packages can also be uploaded manually using theWeb UIor theArtifactory REST API. For Artifactory to handle those packages correctly as PyPI packages they must be uploaded withpypi.nameandpypi.versionProperties.

Automatic extraction of properties

While indexing the newly uploaded packages Artifactory willautomaticallytry to extract required properties from the package metadata saved in the file. Note that not all supported files can be extracted.

Currently, onlyzip, tar, tgz, tar.gz, tar.bz2, eggandwhlfiles can be extracted for metadata.

In addition, indexing starts after a 60 second quiet period, counting from the last upload to the current repository.


Searching for PyPI Packages

Using PIP

Artifactory supports search usingpip'ssearchcommand in local, remote and virtual repositories. For example:

pip search
pip搜索frog-fu——索引http://localhost: 8081美元/artifactory/api/pypi/pypi-virtual/ frog-fu - 0.2a INSTALLED: 0.2a (latest) $ pip search irbench --index http://localhost:8081/artifactory/api/pypi/pypi-virtual/ irbench - Image Retrieval Benchmark.

In this examplefrog-fuis a locally installed package, whileirbenchis found atpypi.org, both repositories aggregated by thepypi-virtualrepository.

Specifying the index

When using the search command, the index should be specified explicitly (without the/simpleat the end), as pip will ignore theindex-urlvariable in itspip.conffile.

Artifactory Search

PyPI packages can also be searched for using Artifactory'sProperty Search. All PyPI packages have the propertiespypi.name,pypi.versionandpypi.summaryset by the uploading client, or later during indexing for supported file types.


Viewing Metadata of PyPI Packages

Artifactory lets you view selected metadata of a PyPI package directly from the UI.

In theArtifactsmoduleTree Browser,drill down to select the file you want to inspect. The metadata is displayed in thePyPI Infotab.

PyPI Info


Working with Remote Repositories with the Custom Registry Suffix

From Artifactory 6.10.3, you can set a custom suffix instead of the default simple like in cases of DevPi.

To set the devpi registry suffix to the server suffix:

Use the root URL in the URL and Registry URL. For example: http://m.devpi.net.

In order to search, include the required scope in the index URL (as in the devpi example, it could be root/pypi).

pip搜索frog-fu——索引http://localhost: 8081美元/artifactory/api/pypi/devpi/root/pypi/

To install, include the desired scope in the index url (like in devpi example, it could be root/pypi)

$ pip install frog-bar -i http://localhost:8081/artifactory/api/pypi/devpi/root/pypi/simple



Watch the Screencast



  • No labels