Skip to main content

Python Development Master

Project description

PDM - Python Development Master

A modern Python package manager with PEP 582 support. 中文版本说明

PDM logo

📖 Documentation

Github Actions PyPI codecov Docker Cloud Build Status Downloads Downloads pdm-managed

asciicast

What is PDM?

PDM is meant to be a next generation Python package management tool. It was originally built for personal use. If you feel you are going well with Pipenv or Poetry and don't want to introduce another package manager, just stick to it. But if you are missing something that is not present in those tools, you can probably find some goodness in pdm.

PEP 582 proposes a project structure as below:

foo
    __pypackages__
        3.8
            lib
                bottle
    myscript.py

There is a __pypackages__ directory in the project root to hold all dependent libraries, just like what npm does. Read more about the specification here.

Highlights of features

  • PEP 582 local package installer and runner, no virtualenv involved at all.
  • Simple and relatively fast dependency resolver, mainly for large binary distributions.
  • A PEP 517 build backend.
  • A full-featured plug-in system.
  • PEP 621 project metadata format.

Why not virtualenv?

The majority of Python packaging tools also act as virtualenv managers to gain the ability to isolate project environments. But things get tricky when it comes to nested venvs: One installs the virtualenv manager using a venv encapsulated Python, and create more venvs using the tool which is based on an encapsulated Python. One day a minor release of Python is released and one has to check all those venvs and upgrade them if required.

PEP 582, on the other hand, introduces a way to decouple the Python interpreter from project environments. It is a relative new proposal and there are not many tools supporting it (one that does is pyflow), but it is written with Rust and thus can't get much help from the big Python community. For the same reason it can't act as a PEP 517 backend.

Installation:

PDM requires python version 3.7 or higher.

If you are on MacOS and using homebrew, install it by:

$ brew install pdm

Otherwise, it is recommended to install pdm in an isolated environment with pipx:

$ pipx install pdm

Or you can install it under a user site:

$ pip install --user pdm

Quickstart

Initialize a new PDM project

$ pdm init

Answer the questions following the guide, and a PDM project with a pyproject.toml file will be ready to use.

Install dependencies into the __pypackages__ directory

$ pdm add requests flask

You can add multiple dependencies in the same command. After a while, check the pdm.lock file to see what is locked for each package.

Run your script with PEP 582 support

Suppose you have a script app.py placed next to the __pypackages__ directory with the following content(taken from Flask's website):

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()

If you are a Bash user, set the environment variable by eval $(pdm --pep582). Now you can run the app directly with your familiar Python interpreter:

$ python /home/frostming/workspace/flask_app/app.py
 * Serving Flask app "app" (lazy loading)
 ...
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Ta-da! You are running an app with its dependencies installed in an isolated place, while no virtualenv is involved.

For Windows users, please refer to the doc about how to make it work.

If you are curious about how this works, check this doc section for some explanation.

Docker image

$ docker pull frostming/pdm

FAQ

1. What is put in __pypackages__?

PEP 582 is a draft proposal which still needs a lot of polishing. For instance, it doesn't mention how to manage CLI executables. PDM makes the decision to put bin and include together with lib under __pypackages__/X.Y.

2. How do I run CLI scripts in the local package directory?

The recommended way is to prefix your command with pdm run. It is also possible to run CLI scripts directly from the outside. PDM's installer has already injected the package path to the sys.path in the entry script file.

3. What site-packages will be loaded when using PDM?

Packages in the local __pypackages__ directory will be loaded before the system-level site-packages for isolation.

4. Can I relocate or move the __pypackages__ folder for deployment?

You'd better not. The packages installed inside __pypackages__ are OS dependent. Instead, you should keep pdm.lock in VCS and do pdm sync on the target environment to deploy.

5. Can I use pdm to manage a Python 2.7 project?

Sure. The pdm itself can be installed under Python 3.7+ only, but it doesn't restrict the Python used by the project.

Badges

Tell people you are using PDM in your project by including the markdown code in README.md:

[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev)

pdm-managed

Credits

This project is strongly inspired by pyflow and poetry.

License

This project is open sourced under MIT license, see the LICENSE file for more details.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdm-1.5.0.post1.tar.gz (560.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdm-1.5.0-py3-none-any.whl (156.1 kB view details)

Uploaded Python 3

File details

Details for the file pdm-1.5.0.post1.tar.gz.

File metadata

  • Download URL: pdm-1.5.0.post1.tar.gz
  • Upload date:
  • Size: 560.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.6

File hashes

Hashes for pdm-1.5.0.post1.tar.gz
Algorithm Hash digest
SHA256 6d382e3f74e4ba5b28e34c11cfec18478e122671149d44f0f8e552f39b257dbf
MD5 b15e917bda4d47ea9a555f0ddec200ef
BLAKE2b-256 2591cb1a16c905479fb9f8f270df6ca48cc0a5d438762aae799d638a7e3c8f67

See more details on using hashes here.

File details

Details for the file pdm-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: pdm-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 156.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

File hashes

Hashes for pdm-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fa92496511387384ed5b5fddea118ef87f3b58c8aa1f5ac35bc9d5d0484c865
MD5 668a33f8ab6a12757f86ba7eed2b1932
BLAKE2b-256 e2f9f224651b5add56908593c25c16175deb55a7f43f4959e3107b5be80f3dec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page