姓名 | 描述 |
---|---|
版本 | 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許可分配。請參閱許可證文件。