本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

Python ドキュメント
Python
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts
ディスカッション

Python ガイド · 4/6

Modules and Packages

この章は現在、英語でのみ提供しています。

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.

この章について質問がありますか?
前の章Types and Data次の章Errors and Testing

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.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。