A sample Python project that serves as a demonstration package for the Python Packaging User Guide
npx @tessl/cli install tessl/pypi-sampleproject@4.0.0A sample Python project that serves as a demonstration package for the Python Packaging User Guide. It provides a basic template structure for Python packages with proper packaging configuration using pyproject.toml, including a simple utility function and CLI entry point to demonstrate modern Python packaging practices.
pip install sampleprojectimport sampleFor specific functions:
from sample import main
from sample.simple import add_onefrom sample import main
from sample.simple import add_one
# Use the utility function
result = add_one(5) # Returns 6
# Call the main entry point function
main() # Prints "Call your main application code here"Command line usage:
# Execute the main entry point via CLI
sampleMain application entry point that prints a placeholder message. This function serves as the primary entry point for the package when used as an application.
def main() -> None:
"""Entry point for the application script"""Simple arithmetic utility function that demonstrates basic package functionality.
def add_one(number: int | float) -> int | float:
"""
Add one to the given number.
Args:
number (int | float): Numeric value to increment
Returns:
int | float: The input number incremented by one
"""The package provides a command line script that executes the main entry point function.
sample
# Executes sample:main function
# No arguments required
# Prints "Call your main application code here"The package includes a sample data file for demonstration purposes.
# Using importlib.resources (Python 3.9+)
from importlib import resources
# Read data file contents
data_content = resources.read_text('sample', 'package_data.dat')
print(data_content) # Output: "some data"
# Get path to data file
with resources.path('sample', 'package_data.dat') as data_path:
print(f"Data file location: {data_path}")Alternative approach using pkg_resources (for older Python versions):
import pkg_resources
# Get path to data file
data_path = pkg_resources.resource_filename('sample', 'package_data.dat')
with open(data_path, 'r') as f:
data_content = f.read()
print(data_content) # Output: "some data"Development extras:
pip install sampleproject[dev] # Includes: check-manifest
pip install sampleproject[test] # Includes: coverage