Skip to main content

magatama-core - Knowledge Graph Engine

PyPI version Python 3.11+ License: MIT

MAGATAMA(YATA のフォーク)の コアライブラリパッケージです(パッケージ名 magatama-core / import 名 magatama_core)。

独立したライブラリとして、コード解析と知識グラフ構築機能を提供します。

特徴

  • 🔍 マルチ言語解析: Python, TypeScript, Rust, Go, Java, C# ほか 24 言語
  • 🕸️ 知識グラフ: NetworkX によるエンティティ・関係性グラフ
  • 🔗 関係性検出: CALLS, IMPORTS, CONTAINS, INHERITS
  • 💾 永続化: JSON / SQLite ストレージ

インストール

pip install magatama-core

オプション言語サポート

# Rust サポート
pip install magatama-core[rust]

# Go サポート
pip install magatama-core[go]

# 全言語サポート
pip install magatama-core[all-languages]

使用方法

基本的な使い方

from magatama_core.infrastructure.parsers import PythonParser
from magatama_core.infrastructure.storage import NetworkXKnowledgeGraph
from magatama_core.application.usecases import ParseFileUseCase

# パーサーとグラフを作成
parser = PythonParser()
graph = NetworkXKnowledgeGraph()

# ユースケースを設定
parse_file = ParseFileUseCase(
    parsers={".py": parser},
    knowledge_graph=graph,
)

# ファイルを解析
from pathlib import Path
result = parse_file.execute(Path("your_file.py"))

print(f"Entities: {result.entity_count}")
print(f"Relationships: {result.relationship_count}")

エンティティの検索

from magatama_core.domain.entities import EntityType

# 関数をすべて取得
functions = list(graph.entities.get_by_type(EntityType.FUNCTION))

# 名前で検索
all_entities = list(graph.entities.all())
matches = [e for e in all_entities if "process" in e.name.lower()]

グラフの永続化

from magatama_core.infrastructure.storage import JSONGraphSerializer

serializer = JSONGraphSerializer()

# 保存
serializer.save(graph, Path("graph.json"))

# 読み込み
loaded_graph = serializer.load(Path("graph.json"))

アーキテクチャ

magatama-core は Clean Architecture に基づいて設計されています:

magatama_core/
├── domain/          # ドメイン層
│   ├── entities/    # FunctionEntity, ClassEntity, etc.
│   ├── value_objects/ # EntityId, Location
│   └── repositories/ # インターフェース
├── application/     # アプリケーション層
│   ├── usecases/    # ParseFileUseCase, etc.
│   └── services/    # Benchmark, etc.
└── infrastructure/  # インフラ層
    ├── parsers/     # PythonParser, TypeScriptParser, etc.
    └── storage/     # NetworkXKnowledgeGraph, SQLiteKnowledgeGraph

対応言語

合計 24 言語に対応しています(主要なものを抜粋)。全一覧は ルート README を参照。

言語 拡張子 パーサー
Python .py PythonParser
TypeScript .ts, .tsx TypeScriptParser
JavaScript .js, .jsx JavaScriptParser
Rust .rs RustParser
Go .go GoParser
Java / C# / C / C++ / Ruby / PHP ほか — (計 24 言語)

ライセンス

MIT License - 詳細は LICENSE を参照してください。

関連プロジェクト

Metadata

Release files for magatama-core 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magatama-core 0.6.0
File Size Uploaded
magatama_core-0.6.0.tar.gz 173.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for magatama-core 0.6.0
File Interpreter ABI Platform
magatama_core-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 324.6 kB

Release files / magatama_core-0.6.0.tar.gz

Download URL magatama_core-0.6.0.tar.gz
Size 173.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c0815eac7ec348cf2b34b11519da1337f77963cdaa654011f7c0684144d03009
BLAKE2b-256 checksum
How to use checksums
d506aaef68cf9ae3e411213978a23e0dbbc3e2fd0b3793aed808302269852bd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / magatama_core-0.6.0-py3-none-any.whl

Download URL magatama_core-0.6.0-py3-none-any.whl
Size 151.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6aa0b6110e4d973c57316abdcde2f5545ddb9d65a5702ae6053089febddbb70c
BLAKE2b-256 checksum
How to use checksums
f606cb3c34c5c50195ec9dd9edf8d48dddd1b2ff274cc71dfbb3b398621f8ef1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page