姓名 | 描述 |
---|---|
版本 | 2.2.0 |
日期: | 2024-09-15 |
来源 | https://github.com/pypiserver/pypiserver |
PYPI | https://pypi.org/project/pypiserver/ |
测试 | https://github.com/pypiserver/pypiserver/actions |
维护者 | @ankostis , @mplanchard , @dee-me-tree-or-love , @pawamoy ,新人吗?我们向新维护者开放! #397 |
执照 | Zlib/libpng +麻省理工学院 |
社区 | https://pypiserver.zulipchat.com |
提示
在讨论中接触或在Zulip上与我们聊天
Pypiserver是PIP或Easy_install的最小PYPI兼容服务器。它基于瓶子,可提供常规目录的包装。可以将车轮,BDIST,鸡蛋和随附的PGP签名与PIP , Setuptools , Tewine , Pypi-Uploader上载,或者简单地用SCP复制。
笔记
为PYPI供电的官方软件是仓库。但是,仓库非常专业,是Pypi.org自己的软件,不应在其他情况下使用。特别是,它不正式支持希望使用自己的软件包的用户用作自定义软件包索引。
Pypiserver实现了与PYPI相同的接口,允许标准的Python包装工具(例如PIP和Twine)就像PYPI一样,将其作为包装索引与PYPI互动,同时使获得运行的索引服务器变得更加容易。
目录
Pypiserver与Python 3.6+和PYPY3一起工作。
较旧的Python版本可能仍然可以使用,但未经过测试。
对于Legacy Python版本,请使用Pypiserver-1.x系列。请注意,这些没有正式支持,也不会收到错误的文件或新功能。
提示
下面的命令在带有posix shell的Unix式操作系统上工作。 “〜”字符扩展到用户的主目录。
如果您使用的是Windows,则必须使用他们的“ Windows对手”。本文档的其余部分也是如此。
使用此命令安装pypiserver
pip install pypiserver # Or: pypiserver[passlib,cache]
mkdir ~ /packages # Copy packages into this directory.
[!提示]另请参阅替代安装方法
将一些软件包复制到您的〜/packages文件夹中,然后将pypiserver启动并运行
pypi-server run -p 8080 ~ /packages & # Will listen to all IPs.
从客户端计算机中,输入此
# Download and install hosted packages.
pip install --extra-index-url http://localhost:8080/simple/ ...
# or
pip install --extra-index-url http://localhost:8080 ...
# Search hosted packages.
pip search --index http://localhost:8080 ...
# Note that pip search does not currently work with the /simple/ endpoint.
[!提示]另请参阅客户端配置,以避免繁琐的打字。
在CMD行中输入PYPI-Server -H以打印详细的用法消息
usage: pypi-server [-h] [-v] [--log-file FILE] [--log-stream STREAM]
[--log-frmt FORMAT] [--hash-algo HASH_ALGO]
[--backend {auto,simple-dir,cached-dir}] [--version]
{run,update} ...
start PyPI compatible package server serving packages from PACKAGES_DIRECTORY. If PACKAGES_DIRECTORY is not given on the command line, it uses the default ~/packages. pypiserver scans this directory recursively for packages. It skips packages and directories starting with a dot. Multiple package directories may be specified.
positional arguments:
{run,update}
run Run pypiserver, serving packages from
PACKAGES_DIRECTORY
update Handle updates of packages managed by pypiserver. By
default, a pip command to update the packages is
printed to stdout for introspection or pipelining. See
the `-x` option for updating packages directly.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Enable verbose logging; repeat for more verbosity.
--log-file FILE Write logging info into this FILE, as well as to
stdout or stderr, if configured.
--log-stream STREAM Log messages to the specified STREAM. Valid values are
stdout, stderr, and none
--log-frmt FORMAT The logging format-string. (see `logging.LogRecord`
class from standard python library)
--hash-algo HASH_ALGO
Any `hashlib` available algorithm to use for
generating fragments on package links. Can be disabled
with one of (0, no, off, false).
--backend {auto,simple-dir,cached-dir}
A backend implementation. Keep the default 'auto' to
automatically determine whether to activate caching or
not
--version show program's version number and exit
Visit https://github.com/pypiserver/pypiserver for more information
在CMD线中输入PYPI-Server Run -H以打印详细的用法
usage: pypi-server run [-h] [-v] [--log-file FILE] [--log-stream STREAM]
[--log-frmt FORMAT] [--hash-algo HASH_ALGO]
[--backend {auto,simple-dir,cached-dir}] [--version]
[-p PORT] [-i HOST] [-a AUTHENTICATE]
[-P PASSWORD_FILE] [--disable-fallback]
[--fallback-url FALLBACK_URL]
[--health-endpoint HEALTH_ENDPOINT] [--server METHOD]
[-o] [--welcome HTML_FILE] [--cache-control AGE]
[--log-req-frmt FORMAT] [--log-res-frmt FORMAT]
[--log-err-frmt FORMAT]
[package_directory [package_directory ...]]
positional arguments:
package_directory The directory from which to serve packages.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Enable verbose logging; repeat for more verbosity.
--log-file FILE Write logging info into this FILE, as well as to
stdout or stderr, if configured.
--log-stream STREAM Log messages to the specified STREAM. Valid values are
stdout, stderr, and none
--log-frmt FORMAT The logging format-string. (see `logging.LogRecord`
class from standard python library)
--hash-algo HASH_ALGO
Any `hashlib` available algorithm to use for
generating fragments on package links. Can be disabled
with one of (0, no, off, false).
--backend {auto,simple-dir,cached-dir}
A backend implementation. Keep the default 'auto' to
automatically determine whether to activate caching or
not
--version show program's version number and exit
-p PORT, --port PORT Listen on port PORT (default: 8080)
-i HOST, -H HOST, --interface HOST, --host HOST
Listen on interface INTERFACE (default: 0.0.0.0)
-a AUTHENTICATE, --authenticate AUTHENTICATE
Comma-separated list of (case-insensitive) actions to
authenticate (options: download, list, update;
default: update).
Any actions not specified are not authenticated, so
to authenticate downloads and updates, but allow
unauthenticated viewing of the package list, you would
use:
pypi-server -a 'download, update' -P
./my_passwords.htaccess
To disable authentication, use:
pypi-server -a . -P .
See the `-P` option for configuring users and
passwords.
Note that when uploads are not protected, the
`register` command is not necessary, but `~/.pypirc`
still needs username and password fields, even if
bogus.
-P PASSWORD_FILE, --passwords PASSWORD_FILE
Use an apache htpasswd file PASSWORD_FILE to set
usernames and passwords for authentication.
To allow unauthorized access, use:
pypi-server -a . -P .
--disable-fallback Disable the default redirect to PyPI for packages not
found in the local index.
--fallback-url FALLBACK_URL
Redirect to FALLBACK_URL for packages not found in the
local index.
--health-endpoint HEALTH_ENDPOINT
Configure a custom liveness endpoint. It always
returns 200 Ok if the service is up. Otherwise, it
means that the service is not responsive.
--server METHOD Use METHOD to run the server. Valid values include
paste, cherrypy, twisted, gunicorn, gevent, wsgiref,
and auto. The default is to use "auto", which chooses
one of paste, cherrypy, twisted, or wsgiref.
-o, --overwrite Allow overwriting existing package files during
upload.
--welcome HTML_FILE Use the contents of HTML_FILE as a custom welcome
message on the home page.
--cache-control AGE Add "Cache-Control: max-age=AGE" header to package
downloads. Pip 6+ requires this for caching.AGE is
specified in seconds.
--log-req-frmt FORMAT
A format-string selecting Http-Request properties to
log; set to '%s' to see them all.
--log-res-frmt FORMAT
A format-string selecting Http-Response properties to
log; set to '%s' to see them all.
--log-err-frmt FORMAT
A format-string selecting Http-Error properties to
log; set to '%s' to see them all.
有关PYPI服务器更新的更多详细信息
usage: pypi-server update [-h] [-v] [--log-file FILE] [--log-stream STREAM]
[--log-frmt FORMAT] [--hash-algo HASH_ALGO]
[--backend {auto,simple-dir,cached-dir}] [--version]
[-x] [-d DOWNLOAD_DIRECTORY] [-u]
[--blacklist-file IGNORELIST_FILE]
[package_directory [package_directory ...]]
positional arguments:
package_directory The directory from which to serve packages.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Enable verbose logging; repeat for more verbosity.
--log-file FILE Write logging info into this FILE, as well as to
stdout or stderr, if configured.
--log-stream STREAM Log messages to the specified STREAM. Valid values are
stdout, stderr, and none
--log-frmt FORMAT The logging format-string. (see `logging.LogRecord`
class from standard python library)
--hash-algo HASH_ALGO
Any `hashlib` available algorithm to use for
generating fragments on package links. Can be disabled
with one of (0, no, off, false).
--backend {auto,simple-dir,cached-dir}
A backend implementation. Keep the default 'auto' to
automatically determine whether to activate caching or
not
--version show program's version number and exit
-x, --execute Execute the pip commands rather than printing to
stdout
-d DOWNLOAD_DIRECTORY, --download-directory DOWNLOAD_DIRECTORY
Specify a directory where packages updates will be
downloaded. The default behavior is to use the
directory which contains the package being updated.
-u, --allow-unstable Allow updating to unstable versions (alpha, beta, rc,
dev, etc.)
--blacklist-file IGNORELIST_FILE, --ignorelist-file IGNORELIST_FILE
Don't update packages listed in this file (one package
name per line, without versions, '#' comments
honored). This can be useful if you upload private
packages into pypiserver, but also keep a mirror of
public packages that you regularly update. Attempting
to pull an update of a private package from `pypi.org`
might pose a security risk - e.g. a malicious user
might publish a higher version of the private package,
containing arbitrary code.
始终在命令行上指定PYPI URL有点麻烦。由于Pypiserver重定向PIP/EASE_INSTALL将其转移到pypi.org索引,如果它没有请求的软件包,则是配置它们始终使用您本地PYPI索引的好主意。
对于pip命令,可以通过在.bashr/.profile/.zshrc中设置环境变量pip_extra_index_url来完成此操作。
export PIP_EXTRA_INDEX_URL=http://localhost:8080/simple/
或通过将以下行添加到〜/.pip/pip.conf
[global]
extra-index-url = http://localhost:8080/simple/
笔记
如果您在没有HTTPS的远程URL上安装了Pypiserver ,则会收到PIP的“不信任”警告,敦促您附加- 受信任的主机选项。您还可以将此选项永久包含在您的配置文件或环境变量中。
对于easy_install命令,您可以在〜/.pydistutils.cfg中设置以下配置
[easy_install]
index_url = http://localhost:8080/simple/
您可以将软件包直接复制到服务器的文件夹(即带有SCP ),而是可以使用Python工具来完成该任务,例如Python Setup.py上传。在这种情况下, Pypiserver负责对上传重新要求进行身份验证。
笔记
我们强烈建议密码保护您的上传!
可以禁用上传的身份验证(例如,在Intranet中)。为避免懒惰的安全性决策,请阅读-p和-a选项的帮助。
首先确保已安装了PassLib模块(请注意, PassLib> = 1.6 ),这是解析-p , -passwords选项指定的Apache Htpasswd文件所需的(请参阅下一步)
pip install passlib
使用此命令使用至少一个用户/密码对创建Apache Htpasswd文件(提示您获取密码)
htpasswd -sc htpasswd.txt < some_username >
提示
在Windows下在Windows下运行htpasswd
CMD或您不在乎的伪造密码,请阅读此问题,因为它们是用于内部服务(从安全角度来看,这仍然是“不好”的...),您可以使用此公共服务
提示
通过API访问Pypiserver时,可以通过Auther Config Flag获得替代身份验证方法。任何可召回的布尔值都可以传递到Pypiserver配置,以提供自定义身份验证。例如,要配置Pypiserver使用Python-PAM进行身份验证
import pam
pypiserver.default_config(auther=pam.authenticate)
有关更多信息,请参阅Using Ad-hoc authentication providers
。
您需要仅使用-P选项重新启动服务器(但是可以随时添加或更新用户/密码对)
./pypi-server run -p 8080 -P htpasswd.txt ~ /packages &
在客户端,编辑或创建具有类似内容的〜/.pypirc文件:
[distutils]
index-servers =
pypi
local
[pypi]
username: < your_pypi_username >
password: < your_pypi_passwd >
[local]
repository: http://localhost:8080
username: < some_username >
password: < some_passwd >
然后从您希望上传的Python-Project的目录中发出此命令:
python setup.py sdist upload -r local
为了避免将密码存储在磁盘上,用清晰的文本可以:您可以:
将寄存器Setuptools的命令与-r选项一样
python setup.py sdist register -r local upload -r local
使用Twine库,该库将过程分为两个步骤。此外,它支持使用PGP签名签名,并将生成的.ASC文件上传到Pypiserver ::
twine upload -r local --sign -identity user_name ./foo-1.zip
从版本1.2.5开始,将为每次推送到main
,Dev,Alpha或Beta版本以及每个最终版本构建官方Docker图像。最新的完整版本将始终在标签最新的标签下可用,当前main
分支将始终在标签不稳定下可用。
您可以随时检查我们的Docker Repo中当前可用的标签。
要使用Docker运行Pypiserver的最新版本,只需
docker run pypiserver/pypiserver:latest run
这启动了Pypiserver在容器内部的/数据 /软件包目录中提供软件包,在容器端口8080上聆听。
除了内部容器端口( -p )以外,容器采用与普通PYPI -Server可执行文件相同的参数,该端口始终为8080。
当然,仅运行一个容器并不有趣。将主机上的端口80映射到容器上的端口8080 ::
docker run -p 80:8080 pypiserver/pypiserver:latest run
现在,您可以在Web浏览器中访问Localhost:80的Pypiserver 。
从主机上的目录中提供包装,例如/封装
docker run -p 80:8080 -v ~ /packages:/data/packages pypiserver/pypiserver:latest run
针对本地.htpasswd文件进行身份验证::
docker run -p 80:8080 -v ~ /.htpasswd:/data/.htpasswd pypiserver/pypiserver:latest run -P .htpasswd packages
您还可以使用ComposeFile指定Pypiserver作为Docker服务运行。提供一个示例组成的文件作为docker-compose.yaml
尝试下面的方法时,首先使用以下命令检查pypiserver的先前版本是否已经存在,并且((选项)卸载它们::
# VERSION-CHECK: Fails if not installed.
pypi-server --version
# UNINSTALL: Invoke again until it fails.
pip uninstall pypiserver
如果PYPI中的最新版本是预发行版,则必须使用PIP的-PRE选项。并更新现有的安装将其与--ignore-installed
pip install pypiserver --pre -I
您甚至可以直接从github使用以下命令安装最新的pypiserver ,假设您已安装了git
pip install git+git://github.com/pypiserver/pypiserver.git
PYPI-Server命令具有更新命令,该命令搜索可用软件包的更新。它扫描包装目录以获取可用的软件包和pypi.org上的搜索以获取更新。没有其他选项, PYPI-Server更新将仅打印一个必须运行的命令列表,以获取每个软件包的最新版本。输出看起来像:
$ ./pypi-server update
checking 106 packages for newer version
.........u.e...........e..u.............
.....e..............................e...
..........................
no releases found on pypi for PyXML, Pymacs, mercurial, setuptools
# update raven from 1.4.3 to 1.4.4
pip -q install --no-deps --extra-index-url https://pypi.org/simple/ -d /home/ralf/packages/mirror raven==1.4.4
# update greenlet from 0.3.3 to 0.3.4
pip -q install --no-deps --extra-index-url https://pypi.org/simple/ -d /home/ralf/packages/mirror greenlet==0.3.4
它首先为每个软件包打印一个字符,然后检查PYPI上的可用版本。点(。)表示包裹是最新的, “ u”意味着可以更新软件包,而“ e”表示PYPI上的发行版列表为空。之后,它显示了一条PIP命令行,可用于更新一个软件包。复制并粘贴该命令,或运行PYPI -Server Update -X,以真正执行这些命令。您需要安装PIP才能工作。
指定额外的-u选项还将允许下载alpha,beta和发布候选人。没有此选项,这些版本将不被考虑。
重要的
默认情况下, Pypiserver每次出现传入的HTTP请求时都会扫描整个软件包目录。对于少数软件包而言,这不是问题,但是在提供数千个软件包时会导致明显的减速。
如果您遇到此问题,可以通过启用Pypiserver的目录缓存功能来获得重大加速。唯一的要求是通过指定CACHE EXTRAS选项::来安装WatchDog软件包,也可以在Pypiserver安装过程中安装。
pip install pypiserver[cache]
可以使用网络服务器的内置缓存功能获得其他加速。例如,如果您将nginx
用作反向Behind a reverse proxy
曲线,则可以轻松启用缓存。例如,允许Nginx最多可缓存10千兆字节的数据,最多1小时:::
proxy_cache_path /data/nginx/cache
levels=1:2
keys_zone=pypiserver_cache:10m
max_size=10g
inactive=60m
use_temp_path=off ;
server {
# ...
location / {
proxy_cache pypiserver_cache ;
proxy_pass http://localhost:8080 ;
}
}
提示
如果您的请求量很高,使用Web服务器缓存特别有用。使用NGINX缓存,现实世界中的Pypiserver安装能够在峰值负载下轻松支持1000多个软件包下载。
有多种选择用于处理系统启动时Pypiserver的自动启动。最常见的两个是Linux系统的SystemD和主管。对于Windows创建脚本的服务,没有第三方工具(例如NSSM) ,这并不是一件容易的事。
SystemD默认是在大多数现代Linux系统上安装的,因此,它是管理Pypiserver流程的绝佳选择。 Systemd的示例配置文件可以在下面看到
[Unit]
Description=A minimal PyPI server for use with pip/easy_install.
After=network.target
[Service]
Type=simple
# systemd requires absolute path here too.
PIDFile=/var/run/pypiserver.pid
User=www-data
Group=www-data
ExecStart=/usr/local/bin/pypi-server run -p 8080 -a update,download --log-file /var/log/pypiserver.log -P /etc/nginx/.htpasswd /var/www/pypi
ExecStop=/bin/kill -TERM $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
WorkingDirectory=/var/www/pypi
TimeoutStartSec=3
RestartSec=5
[Install]
WantedBy=multi-user.target
调整路径并将此文件添加为pypiserver.service。在您的SystemD/System Directory中,将允许使用SystemCtl (例如SystemCtl start pypiserver)管理Pypiserver进程。
有关SystemD的更多有用信息,请访问https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-manage-systemd-systemd-services-and-services-and-unit
主管可以成为纯粹的Python软件包,因此,它为过程管理提供了出色的跨平台支持。下面给出了主管的示例配置文件
[program:pypi]
command=/home/pypi/pypi-venv/bin/pypi-server run -p 7001 -P /home/pypi/.htpasswd /home/pypi/packages
directory=/home/pypi
user=pypi
autostart=true
autorestart=true
stderr_logfile=/var/log/pypiserver.err.log
stdout_logfile=/var/log/pypiserver.out.log
从那里开始,可以使用SubstisorCtl通过主管来管理该过程。
对于Windows,从https://nssm.cc unzip下载NSSM到所需的位置,例如程序文件。确定您要使用win32
还是win64
,然后将exe
添加到环境PATH
。
创建一个start_pypiserver.bat
pypi-server run -p 8080 C: P ath T o P ackages &
提示
在创建服务之前先运行批处理文件。确保您可以远程访问服务器并安装软件包。如果可以的话,请继续进行,如果不是进行故障排除,直到您可以进行故障。在将NSSM添加到混音中之前,这将确保您知道服务器的工作原理。
从命令提示
nssm install pypiserver
此命令将启动NSSM GUI应用程序
Path: C: P ath T o s tart_pypiserver.bat
Startup directory: Auto generates when selecting path
Service name: pypiserver
还有更多选项卡,但这是基本设置。如果服务需要使用一定的登录凭据运行,请确保您在“登录”选项卡中输入这些凭据。
开始服务
nssm start pypiserver
提示
其他有用的命令
nssm --help
nssm stop < servicename >
nssm restart < servicename >
nssm status < servicename >
有关详细信息,请访问https://nssm.cc
瓶网络服务器支持许多WSGI服务器,包括糊状,樱桃,扭曲和Wsgiref (Python的一部分);您可以使用-Server标志选择它们。
您可以使用以下交互式代码查看所有支持的WSGI服务器
>> > from pypiserver import bottle
>> > list ( bottle . server_names . keys ())
[ 'cgi' , 'gunicorn' , 'cherrypy' , 'eventlet' , 'tornado' , 'geventSocketIO' ,
'rocket' , 'diesel' , 'twisted' , 'wsgiref' , 'fapws3' , 'bjoern' , 'gevent' ,
'meinheld' , 'auto' , 'aiohttp' , 'flup' , 'gae' , 'paste' , 'waitress' ]
如果以上服务器都不符合您的需求,请仅调用pypiserver:app()方法,该方法在不启动服务器的情况下返回内部WSGI-APP - 然后,您可以将其发送到您喜欢的任何WSGI服务器。另请阅读使用API部分。
下面给出了一些示例 - 您可能会在瓶网站中找到更多详细信息。
要将Apache2与Pypiserver一起使用,请选择使用瓶文档中解释的MOD_WSGI 。
笔记
如果您选择使用mod_proxy ,请注意,您可能会遇到前缀路径问题(请参阅#155)。
适应并将以下Apache配置放入顶级范围,或在某些<VirtualHost>
内部(由Thomas Waldmann贡献):
WSGIScriptAlias / /yoursite/wsgi/pypiserver-wsgi.py
WSGIDaemonProcess pypisrv user=pypisrv group=pypisrv umask=0007
processes=1 threads=5 maximum-requests=500
display-name=wsgi-pypisrv inactivity-timeout=300
WSGIProcessGroup pypisrv
WSGIPassAuthorization On # Required for authentication (https://github.com/pypiserver/pypiserver/issues/288)
< Directory /yoursite/wsgi >
Require all granted
< /Directory >
或者,如果使用较旧的Apache <2.4 ,请用此::替换最后一部分::
< Directory /yoursite/wsgi >
Order deny,allow
Allow from all
< /Directory >
然后创建/yoursite/cfg/pypiserver.wsgi文件,并确保wsgidaemonprocess指令的用户和组(示例中的pypisrv:pypisrv )具有上述读取许可
import pypiserver
conf = pypiserver . default_config (
root = "/yoursite/packages" ,
password_file = "/yoursite/htpasswd" , )
application = pypiserver . app ( ** conf )
[!tip]如果您已在Virtualenv中安装了Pypiserver ,请按照以下方式遵循MOD_WSGI的说明,并在上面使用以下python代码。
import site site . addsitedir ( '/yoursite/venv/lib/pythonX.X/site-packages' )
笔记
出于安全原因,请注意,目录指令单独授予访问WSGI启动脚本的目录;别无其他。
笔记
要在Apache上启用HTTPS支持,请配置包含WSGI配置的指令以使用SSL。
以下命令使用枪支启动pypiserver
gunicorn -w4 ' pypiserver:app(root="/home/ralf/packages") '
或使用多个根部
gunicorn -w4 ' pypiserver:app(root=["/home/ralf/packages", "/home/ralf/experimental"]) '
粘贴允许在不同的URL路径下运行多个WSGI应用程序。因此,可以在不同的路径上使用不同的软件包。
以下示例paste.ini可用于在不同路径上提供稳定且不稳定的软件包
[composite:main]
use = egg:Paste#urlmap
/unstable/ = unstable
/ = stable
[app:stable]
use = egg:pypiserver#main
root = ~ /stable-packages
[app:unstable]
use = egg:pypiserver#main
root = ~ /stable-packages
~ /unstable-packages
[server:main]
use = egg:gunicorn#main
host = 0.0.0.0
port = 9000
workers = 5
accesslog = -
笔记
您需要安装更多的依赖项才能工作,例如::
pip install paste pastedeploy gunicorn pypiserver
服务器可以从
gunicorn_paster paste.ini
您也可以在反向代理后面运行pypiserver 。
扩展您的nginx配置
upstream pypi {
server pypiserver.example.com:12345 fail_timeout=0 ;
}
server {
server_name myproxy.example.com ;
location / {
proxy_set_header Host $host : $server_port ;
proxy_set_header X-Forwarded-Proto $scheme ;
proxy_set_header X-Real-IP $remote_addr ;
proxy_pass http://pypi ;
}
}
从Pypiserver 1.3开始,您也可以使用反向代理配置中的X-Forwarded-Host
标头来更改基本URL。例如,如果您想在服务器上的特定路径下托管pypiserver
upstream pypi {
server localhost:8000 ;
}
server {
location /pypi/ {
proxy_set_header X-Forwarded-Host $host : $server_port /pypi ;
proxy_set_header X-Forwarded-Proto $scheme ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
proxy_set_header X-Real-IP $remote_addr ;
proxy_pass http://pypi ;
}
}
使用反向代理是使Pypiserver在HTTPS后面的首选方法。例如,使用nginx
将pypiserver放在端口443上的https后面,并使用自动HTTP重定向
upstream pypi {
server localhost:8000 ;
}
server {
listen 80 default_server ;
server_name _ ;
return 301 https:// $host$request_uri ;
}
server {
listen 443 ssl ;
server_name pypiserver.example.com ;
ssl_certificate /etc/star.example.com.crt ;
ssl_certificate_key /etc/star.example.com.key ;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 ;
ssl_ciphers HIGH: ! aNULL: ! MD5 ;
location / {
proxy_set_header Host $host : $server_port ;
proxy_set_header X-Forwarded-Proto $scheme ;
proxy_set_header X-Real-IP $remote_addr ;
proxy_pass http://pypi ;
}
}
提示
有关更多详细信息,请参阅NGINX的HTTPS文档。
可以使用certbot和letsencrypt来简化获得和保持证书的最新状态。
也可以使用traefik将pypiserver在端口443上放置在HTTPS后面,并使用Docker组成的自动HTTP重定向。请参阅提供的docker-compose.yml示例以获取更多信息。
为了启用临时身份验证支持者或使用瓶子外的WSGI服务器,您需要通过其API启动Pypiserver 。
配置pypiserver的主要入口点是pypiserver:app()函数。此功能返回您的内部WSGI应用,然后将您发送给您喜欢的任何WSGI服务器。
要获取所有pypiserver:app()关键字及其说明,请阅读函数pypiserver:default_config()
最后,要使用配置的应用程序启动WSGI服务器,请调用瓶子:运行(应用,主机,端口,服务器)功能。请注意, Pypiserver用自己的瓶子副本船;要使用它,请这样导入:从pypiserver进口瓶中
Pypiserver的Auther关键字:App()函数可能仅使用API设置。当通过用户名和给定请求的密码时,这可以是任何可返回布尔值的可召回的。
例如,要根据UNIX下的/etc /passwd文件对用户进行身份验证,您可以通过以下步骤将此类决定委派给Python-PAM库:
确保安装Python-PAM模块
pip install python-pam
沿着这些线创建一个python script
$ cat > pypiserver-start.py
import pypiserver
from pypiserver import bottle
import pam
app = pypiserver.app(root= ' ./packages ' , auther=pam.authenticate)
bottle.run(app=app, host= ' 0.0.0.0 ' , port=80, server= ' auto ' )
[Ctrl+ D]
调用Python-Script启动Pypiserver
python pypiserver-start.py
笔记
Python-PAM模块需要读取访问/etc /shadow文件;您可以将pypiserver列入阴影组的用户添加,并带有这样的命令: sudo usermod -a -g shadow pypy -user 。
用于嵌入式设备的微型解释器可以使用Module Upip.py安装软件包。该模块使用专门的JSON-ENDPOINT检索软件包信息。该端点由Pypiserver支持。
可以用Micropython的Unix端口进行测试
cd micropython
ports/unix/micropython -m tools.upip install -i http://my-server:8080 -p /tmp/mymodules micropython-foobar
以这种方式安装嵌入式设备的补制包装:
import network
import upip
sta_if = network . WLAN ( network . STA_IF )
sta_if . active ( True )
sta_if . connect ( '<your ESSID>' , '<your password>' )
upip . index_urls = [ "http://my-server:8080" ]
upip . install ( "micropython-foobar" )
可以在此处找到有关Micropython包装的更多信息:https://docs.micropython.org/en/latest/reference/packages.html
Pypiserver在/健康方面提供默认的健康终点。如果服务已启动,它总是会返回200个正常。否则,这意味着该服务没有响应。
此外, Pypiserver允许用户自定义健康端点。允许使用字母数字字符,连字符,前向斜线和下划线,并且端点不应与任何现有路线重叠。有效示例: /healthz , /health /live-1 , /api_health , /action /health
使用-Health-endpoint参数运行Pypiserver:
pypi-server run --health-endpoint /action/health
import pypiserver
from pypiserver import bottle
app = pypiserver . app ( root = "./packages" , health_endpoint = "/action/health" )
bottle . run ( app = app , host = "0.0.0.0" , port = 8080 , server = "auto" )
尝试卷曲http:// localhost:8080/Action/Health
要创建存储库的副本,请使用
git clone https://github.com/pypiserver/pypiserver.git
cd pypiserver
要接收以后的任何更改,在上述文件夹中使用:
git pull
重要的
pypiserver并未实现PYPI上看到的完整API。它实现了足以制作easy_install , pip安装和搜索工作。
已知以下限制:
请使用GitHub的错误跟踪器,以获取其他错误。
还有许多其他项目,可让您运行自己的PYPI服务器。如果Pypiserver对您不起作用,则以下是最受欢迎的替代方案之一:
DevPi-Server:可靠的快速pypi.org缓存服务器,这是综合GitHub风格的PYPI索引服务器和包装元工具的一部分。 (版本:2.1.4,访问日期:8/3/2015)
检查这个问题:如何滚动我自己的pypi
这些项目曾经是pypiserver的替代品,但现在是未受欢迎的或存档的。
PIP2PI一种简单的CMD线工具,该工具从PIP要求中构建了与PIPI兼容的本地文件夹
Blask-pypi-proxy是PYPI的代理,还可以上传自定义软件包。
尽管不是Pypiserver用作索引服务器的直接替代方案,但以下是您可能想熟悉的相关软件项目的列表:
PYPI-UPLOADER:一种命令行实用程序,可将软件包从PYPI上传到您的Pypiserver ,而不必首先在本地存储它们。
麻线:用于与PYPI或PYPISERVER互动的命令行实用程序。
仓库:为PYPI本身提供动力的软件。它通常不打算由最终用户运行。
Pypiserver包含根据MIT许可证可用的瓶子副本,其余部分则根据Zlib/libpng许可分配。请参阅许可证文件。