Zum Hauptinhalt springen
ProdukteDesktop-WerkzeugeTASTECADZeichnungsprüfungTASTEFILESDateiverwaltungTASTEFTPDateiübertragungTASTESSHRemote-ArbeitsbereichTASTEZIPKomprimieren und EntpackenTASTEWINMDateiverwaltungEntwicklerwerkzeugeTASTECODEIntegrierte Entwicklungsumgebung für RustTASTESTUDIOIntegrierte Entwicklungs- und TestumgebungTASTEETLDatenintegration (ETL)ServerTASTEREMOTERemote-Desktop-ServerTASTEGEOGeodatenserverTASTEMAILE-Mail-ArbeitsbereichInvestierenTASTESTOCKDesktop-App für automatischen AktienhandelErste SchritteDownloadsDokumentationKaufenAlle Produkte
Marktplatz
Neuigkeiten
TechnikNeuigkeitenEntwickler-News von heuteEntwicklerdokuProgrammiersprachenRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb-Frontend-FrameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer-FrameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp- & Desktop-FrameworksTauriFlutterReact NativeElectronAlgorithmenAlgorithmus-GrundlagenKernalgorithmenFortgeschrittene AlgorithmenAlgorithmen für die Praxis
CommunityProjekteEntwicklungslogsPromptsProbleme mit KI-ToolsShowcaseCommunity-Leitfaden
ZusammenarbeitWissenstransferWebsite-AufbauDesktop-App-AufbauRelease- und ZahlungspipelineVertriebspartnerKontakt
DiensteRemote-DesktopIndividuelle Installationspakete
TASTEDEV
Produkte

Desktop-Werkzeuge

TASTECADKomplexe Zeichnungen, mühelos geöffnetTASTEFILESNur die Dateien, die zählen – in BestzeitTASTEFTPDer aufgeräumteste Weg für Ihre DateienTASTESSHDie stärkere Verbindung zu Ihren ServernTASTEZIPSchneller packen, sicherer entpackenTASTEWINMEin tastaturorientierter Dateimanager mit zwei Fenstern

Entwicklerwerkzeuge

TASTECODERust-Apps bearbeiten, bauen, debuggen und testen – alles in einem FensterTASTESTUDIOVom Bearbeiten bis zu Remote-Tests und freigegebenen KI-KorrekturenTASTEETLDaten bewegen, die Werte im Blick

Server

TASTEREMOTEEin Remote-Desktop auf Ihrem eigenen ServerTASTEGEOEin GeoServer-kompatibler Geodatenserver, neu aufgebaut in RustTASTEMAILIhre E-Mail wieder in Ihrer Hand

Investieren

TASTESTOCKAutomatischer Aktienhandel nach Ihren Regeln: wann und was

Erste Schritte

DownloadsNeueste Versionen aller ProdukteDokuSo nutzen Sie jedes ProduktKaufenAbos und DauerlizenzenAlle ProdukteAlle Produkte im Überblick
Alle Produkte
MarktplatzNeuigkeiten
Technik

Neuigkeiten

Entwickler-News von heuteOffizielle Meldungen zu Sprachen, Frameworks, GitHub und KIEntwicklerdokuAnleitungen zu Sprachen, Frameworks und Algorithmen

Programmiersprachen

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web-Frontend-FrameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server-FrameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App- & Desktop-FrameworksTauriFlutterReact NativeElectron

Algorithmen

Algorithmus-GrundlagenKomplexitätsanalyse · Sortieren · Suchen · Grundlegende Datenstrukturen · Bäume und HeapsKernalgorithmenGraphtraversierung · Kürzeste Wege und minimale Spannbäume · Dynamische Programmierung · Greedy-Algorithmen · Teile und herrsche · BacktrackingFortgeschrittene AlgorithmenZeichenkettenalgorithmen · Mathematik und Zahlentheorie · Bitmanipulation · Segmentbäume · Union-FindAlgorithmen für die PraxisStrategie für Coding-Interviews · LRU-Cache · Rate Limiting · Konsistentes Hashing
Alle Entwicklungsdokumente
Community
ProjekteEntwickler und Projekte entdeckenEntwicklungslogsEntscheidungen und ErkenntnissePromptsWiederverwendbare AnweisungenProbleme mit KI-ToolsProbleme und Workarounds für Claude, Codex, GeminiShowcaseFertige ErgebnisseCommunity-LeitfadenWie wir offen entwickeln
Zusammenarbeit
WissenstransferNative Apps mit Rust und eguiWebsite-Aufbau10 Sprachen, Konten, Dokumentation und DownloadsDesktop-App-AufbauRust und egui, ohne WebViewRelease- und ZahlungspipelineSignatur, MSI, deb, rpm, AppImage, PrüfsummenVertriebspartnerEmpfehlen und 30 % erhaltenKontaktEntwicklung, Partnerschaft, Investition
Dienste
Remote-DesktopIhren Computer im Browser erreichenIndividuelle InstallationspaketeNur nötige Funktionen, Einstellungen vorab
Kaufen
DE
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Anmelden
Anmelden
TASTEDEV

Von kleinen Werkzeugen zu besserer Entwicklung.

support@tastedev.netTASTEDEV unterstützen
ProdukteProduktübersichtKaufenDokuDownloadsMarktplatzSupport
CommunityProjekteEntwicklungslogsPromptsProbleme mit KI-ToolsShowcase
RichtlinienÜber unsDatenschutzerklärungNutzungsbedingungenAbo-BedingungenRückerstattungCommunity-Richtlinien
KontoAnmeldenRegistrieren
Besucher
Heute
Gestern
Aufrufe gesamt
Firma
GXSOFT
Vertretungsberechtigt
CHOI YOUNG GU
Handelsregisternummer
853-44-00368
Anschrift
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefon
+82-10-4404-1523
E-Mail
whitecalvin@tastedev.net
Datenschutzbeauftragter
CHOI YOUNG GU

© 2026 TASTEDEVProduktinformationen basieren auf verifizierten Entwicklungsquellen.Veröffentlicht · wird verbessert

Python-Dokumentation
Python
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts
Diskussionen

Python-Anleitung · 4/6

Modules and Packages

Dieses Kapitel ist vorerst nur auf Englisch verfügbar.

Sooner or later a project outgrows a single file. You split code across modules, pull in third-party libraries, and maybe publish something of your own. This chapter covers how modules and packages are organized, the different forms of import, managing dependencies with pip and requirements files, describing a project in pyproject.toml, and the basics of publishing to PyPI.

Modules and packages

Every .py file is a module, and its file name without the extension is the module name. A package is a directory of modules, usually containing an __init__.py file. That file can be empty, or it can run setup code and choose which names the package exposes.

myapp/
    pyproject.toml
    src/
        myapp/
            __init__.py
            cli.py
            text/
                __init__.py
                slug.py
    tests/
        test_slug.py

Placing the package under src/ is known as the src layout. It prevents tests from accidentally importing your working copy instead of the installed package, which is why many library authors prefer it.

Importing

import comes in a few flavors. A module's top-level code runs only the first time it is imported; later imports reuse the cached module object.

import json                          # the whole module
import datetime as dt                # with an alias
from pathlib import Path             # a single name
from collections import Counter, defaultdict

data = json.loads('{"a": 1}')
today = dt.date.today()
config = Path("config") / "app.toml"

Inside a package, modules can refer to their siblings with relative imports. A single dot means the current package and two dots mean its parent.

# src/myapp/text/slug.py
import re


def slugify(title: str) -> str:
    return re.sub(r"[^a-z0-9]+", "-", title.lower()).strip("-")


# src/myapp/cli.py
from .text.slug import slugify


def main() -> None:
    print(slugify("Hello Python World"))  # hello-python-world

Avoid from module import *: it hides where names come from and can silently shadow your own. If two modules import each other, you may hit circular import errors; the usual cure is moving the shared code into a third module.

pip and requirements files

To reproduce an application on another machine, you need a list of its dependencies. The simplest format is a requirements.txt file.

# record every installed package with its exact version
python -m pip freeze > requirements.txt

# recreate the same set somewhere else
python -m pip install -r requirements.txt

pip freeze pins everything, including indirect dependencies. Exact pins suit deployed applications; libraries should declare looser ranges so they play well with other packages. Tools such as pip-tools, Poetry and uv automate this pinning and keep lock files up to date.

pyproject.toml

pyproject.toml is the standard configuration file for a Python project. It holds the name, version, dependencies, build backend and command-line entry points in one place, and many tools, including pytest, Ruff and mypy, read their settings from it too.

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "myapp"
version = "0.1.0"
description = "Small text utilities"
readme = "README.md"
dependencies = [
    "requests",
]

[project.optional-dependencies]
dev = ["pytest", "mypy"]

[project.scripts]
myapp = "myapp.cli:main"

The [build-system] table names the backend that builds your package, while [project] carries metadata and runtime dependencies. You can state the supported Python range with a requires-python field. Each entry under [project.scripts] becomes a terminal command once installed. During development, an editable install means source changes take effect without reinstalling.

python -m pip install -e ".[dev]"
myapp   # hello-python-world

Publishing basics

Uploading to PyPI lets anyone install your package with pip. The usual workflow:

  1. Check that the name in pyproject.toml is not already taken on PyPI.
  2. Run build to produce a source distribution and a wheel in dist/.
  3. Upload to TestPyPI first and try installing from there.
  4. Once everything looks right, upload to the real PyPI, authenticating with an API token rather than a password.
python -m pip install build twine
python -m build
python -m twine upload --repository testpypi dist/*
python -m twine upload dist/*

Summary

  • A .py file is a module; a directory of modules is a package.
  • Use plain, aliased, from and relative imports as appropriate, and avoid import *.
  • Pin application dependencies, for example in requirements.txt, so environments are reproducible.
  • Describe the project in pyproject.toml, then publish with build and twine.
Fragen zu diesem Kapitel?
Vorheriges KapitelTypes and DataNächstes KapitelErrors and Testing

0 Kommentare

Top-KommentareNeueste zuerst

Anmelden · Melde dich an, um einen Kommentar zu schreiben.