You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

To maintain order in Search API we added the pyproject.toml, this file serves as a central configuration file for Python projects, providing a standardized way to define project metadata, build configurations, dependency management, and other project-specific settings. It helps streamline project development, build processes, and collaboration among developers.


Step-by-step guide

For each new dependency 

  1. Execute pip install   <dependency>
  2. Go to pyproject.toml and look for the dependency section

    We recommend using version specific definition, if for some reason you need more flexibility on a dependency please check Dependency specifiers

  3. Once your library is in the dependencies section future developer will be able to install all necessary dependencies with

    pip install -e .

You can use requirements file, but we don't recommend this, the use of the pyproject ensures a double check on the dependencies to install, and ins


Why use Pyproject over Requirements file

The pyproject.toml file and requirements.txt serve different purposes when it comes to managing dependencies in Python projects. Here are some advantages of using pyproject.toml over requirements.txt:

1. Enhanced Dependency Management: pyproject.toml provides a more robust and flexible dependency management system compared to requirements.txt. It allows specifying dependencies with version constraints, specifying compatible Python versions, and managing transitive dependencies more accurately. This helps ensure consistent and reliable dependency resolution.

2. Environment Isolation: pyproject.toml is often used in conjunction with build systems like poetry or flit that support virtual environments and isolation. It allows you to create and manage project-specific virtual environments, ensuring that the project's dependencies are isolated from other Python installations on your system. This helps prevent conflicts between different projects and provides better reproducibility.

3. Build System Integration: pyproject.toml integrates seamlessly with modern build systems, providing a unified configuration file for the entire project. Build systems like poetry can automatically handle dependency installation, build processes, and packaging based on the pyproject.toml file. This simplifies the build and distribution workflow and reduces manual intervention.

4. Project Metadata and Documentation: pyproject.toml supports adding project metadata, such as project name, version, author, and description. This information is valuable for package managers, documentation generation tools, and project discovery. pyproject.toml allows you to include additional project-specific settings and configuration, making it a more comprehensive and informative file for your project.

5. Standardization and Future Compatibility: pyproject.toml is based on the PEP 518 standard, which aims to provide a consistent and extensible configuration format for Python projects. By adopting pyproject.toml, you align with the industry standards and ensure compatibility with future tooling and build systems that support this format.

While requirements.txt is a simpler and widely used approach for specifying dependencies, pyproject.toml offers more advanced features, better integration with build systems, and improved dependency management capabilities. It is especially beneficial for larger projects, complex dependency trees, and projects that require reproducibility, isolation, and consistent build processes.

Related articles

  • No labels