Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Cloud Registry
  • Getting started
    • All guides
        • Setting up PyPI
        • Creating a Python package
        • Pushing a Python package to a registry
        • Pulling a Python package from a registry
        • Deleting a Python package from a registry
        • Examples of working with PyPI registries
    • Creating a lifecycle policy
  • Access management
  • Pricing policy
  • Terraform reference
  • Audit Trails events

In this article:

  • Python package structure
  • Creating a package
  • What's next
  1. Step-by-step guides
  2. Managing artifacts
  3. Python artifact
  4. Creating a Python package

Creating a Python package

Written by
Yandex Cloud
Updated at May 26, 2026
  • Python package structure
  • Creating a package
  • What's next

This guide describes how to create a Python package for publishing to a Cloud Registry.

Python package structurePython package structure

Here is an example of a project structure:

my_package/              # Project root directory
│
├── my_package/          # Main package (its name must match the project name)
│   ├── __init__.py      #   Makes the directory a Python package
│   └── core.py          # Main module (optional)
│
├── tests/               # Test directory
│   ├── __init__.py
│   └── test_core.py     # Tests for core.py
│
├── README.md            # Project description
├── LICENSE              # License
└── pyproject.toml       # Project metadata

Creating a packageCreating a package

pip + twine
Poetry
uv
  1. Set up your environment:

    apt update && \
        apt-get install python3 -y && \
        apt-get install python3.12-venv -y && \
        python3 -m ensurepip --default-pip
    
  2. Install build tools:

    python3 -m venv my-venv && source my-venv/bin/activate
    pip install build twine
    
  3. Create the project structure:

    mkdir -p my_package/my_package
    cd my_package
    
  4. Create a file named my_package/__init__.py:

    cat > my_package/__init__.py << 'EOF'
    def hello():
        print("Hello from my package!")
    EOF
    
  5. Create a file named pyproject.toml:

    cat > pyproject.toml << 'EOF'
    [build-system]
    requires = ["setuptools"]
    build-backend = "setuptools.build_meta"
    
    [project]
    name = "my_package"
    version = "0.0.1"
    description = "A small example package"
    readme = "README.md"
    
    [project.scripts]
    my_package = "my_package:hello"
    EOF
    
  6. Create a file named README.md:

    cat > README.md << 'EOF'
    # my_package
    A small example package.
    EOF
    
  7. Build the package:

    python3 -m build
    

    Result:

    Successfully built my_package-0.0.1.tar.gz and my_package-0.0.1-py3-none-any.whl
    

    The built files will appear in the dist/ directory.

  8. Check the package:

    twine check dist/*
    

    Result:

    Checking dist/my_package-0.0.1-py3-none-any.whl: PASSED
    Checking dist/my_package-0.0.1.tar.gz: PASSED
    
  1. Install Poetry:

    curl -sSL https://install.python-poetry.org | python3 -
    
  2. Create a new project:

    poetry new my_package
    cd my_package
    

    Poetry will automatically create the project structure with a file named pyproject.toml.

  3. Edit pyproject.toml:

    [tool.poetry]
    name = "my_package"
    version = "0.0.1"
    description = "A small example package"
    authors = ["Example Author <author@example.com>"]
    readme = "README.md"
    
    [tool.poetry.dependencies]
    python = "^3.9"
    
    [build-system]
    requires = ["poetry-core"]
    build-backend = "poetry.core.masonry.api"
    
  4. Create a file named mypackage/__init__.py:

    def hello():
        return "Hello from my package!"
    
  5. Build the package:

    poetry build
    

    Result:

    Building my_package (0.0.1)
      - Building sdist
      - Built my_package-0.0.1.tar.gz
      - Building wheel
      - Built my_package-0.0.1-py3-none-any.whl
    
  1. Install uv:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    

    Alternatively, you can use pip:

    pip install uv
    
  2. Create a new project:

    uv init mypackage --lib && cd mypackage
    
  3. Create a virtual environment:

    uv venv && source .venv/bin/activate
    
  4. Create a file named mypackage/__init__.py:

    cat > src/mypackage/__init__.py << 'EOF'
    def hello(name: str = "World") -> str:
        return f"Hello, {name}!"
    
    def add(a: int, b: int) -> int:
        return a + b
    EOF
    
  5. Build the package:

    uv build
    

    Result:

    Building my_package-0.0.1.tar.gz and my_package-0.0.1-py3-none-any.whl
    

What's nextWhat's next

  • Pushing a Python package to a local registry in Cloud Registry
  • Pulling a Python package from a Cloud Registry
  • Examples of working with PyPI registries

Was the article helpful?

Previous
Setting up PyPI
Next
Pushing a Python package to a registry
© 2026 Direct Cursus Technology L.L.C.