- Getting Started
- Installing Pants
- Setting Up Pants
- Tutorial
- Common Tasks
- Pants for Organizations
- Pants Basics
- Why Use Pants?
- Pants Concepts
- BUILD files
- Target Addresses
- Third-Party Dependencies
- Pants Options
- Invoking Pants
- Reporting Server
- IDE Support
- JVM Support
- Python Support
- Go support for Pants
- Node.js Support
- Code & Doc Generation
- Thrift
- Python gRPC + protobufs
- Markdown
- Getting Help
- Troubleshooting
- Community
- Reference
- Pants BUILD Dictionary
- Pants Reference
- Release Notes
- Developer
- Pants Developer Center
- Export Format
- Architecture
- Blogs
- Twitter's Coursier Migration
Define a Python Library Target
Problem
You need to turn your Python project into a library target that other libraries in your Pants workspace can use as a dependency.
If you need to create an executable Python binary target instead, see Specify a Python Executable (PEX).
Solution
Define a python_library target definition that designates the library's source files, dependencies, and more.
Discussion
A python_library target definition should specify the following:
- A
namefor the target - Either a single
sourcePython file or a list ofsources - A list of
dependencies(optional)
Here is an example target definition:
python_library( name='my-python-lib', sources=['*.py'], dependencies=[ 'src/python/myproject/server:server-lib', 'src/python/myproject/client:client-lib', 'src/static/json:config', ], )
Now, another library or binary can depend on the target you created:
dependencies=[ 'src/python/myproject/example:my-python-lib', ]
See Also
Generated by publish_docs
from dist/markdown/html/src/docs/common_tasks/python_library.html 2022-12-03T01:09:00.303355
