jac-python-interop

Integrates Python and Jac code bidirectionally using imports, inline blocks, and jaclang.lib.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/PMN123/trapdoor --skill jac-python-interop-pmn123
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jac-python-interop
Source: https://github.com/PMN123/trapdoor/tree/main/.agents/skills/jac-python-interop
Command: npx skills add https://github.com/PMN123/trapdoor --skill jac-python-interop-pmn123

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Mixing Jac and Python code raises practical questions: how to import PyPI packages from Jac, how to call Jac modules from Python scripts, how to subclass metaclass-driven Python types, and how to handle untyped Python values crossing into Jac's strict type system. This Skill documents the full interop surface so these boundaries work without guesswork. ## Core Features & Use Cases - PyPI imports from Jac: Import numpy, pandas, sklearn, or any installed package with plain import syntax, plus guidance on stub packages and the untyped any boundary (E1001). - Inline Python and class archetypes: Embed legacy Python verbatim with ::py:: blocks, or use the class archetype with static has when subclassing metaclass-driven Python types like Pygments lexers. - Jac from Python scripts: Import .jac modules via the automatic import hook and use jaclang.lib primitives (Node, Walker, spawn, root, connect), with jac2py for translating Jac to library-mode Python. - Use Case: A team migrating a Python codebase to Jac keeps a tested validation function in a ::py:: block, imports scikit-learn directly for a model node, and hands a jac2py output module to the Python-only backend team. ## Quick Start Ask the AI to show how to import a PyPI package like numpy into a Jac file and call it from a with entry block.

Frequently Asked Questions about jac-python-interop

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I import Python packages like numpy or pandas in Jac?

Use plain import syntax in Jac, such as `import numpy as np;` or `import from sklearn.linear_model { LinearRegression }`. Jac compiles to Python bytecode, so any installed PyPI package works without wrappers or FFI.

How to import a Jac module from a Python script?

A .pth file installed with jaclang registers an import hook, so .jac modules import directly in Python. Use jaclang.lib for graph primitives like Node, Walker, spawn, and connect, and call root() as a function in library mode.

When should I use class instead of obj in Jac?

Use the class archetype when subclassing a Python type whose metaclass consumes class attributes, such as Pygments RegexLexer or ORM base classes. In a class, `static has` creates genuine class attributes that the metaclass can read; obj fields would be invisible to it.

Why does Jac report E1001 when calling untyped Python functions?

Untyped Python returns arrive as `any`, and Jac's strict mode blocks `any` from flowing into typed destinations. Fix it by adding a .pyi stub, narrowing with isinstance, or casting with `value as Type`.

Why do relative imports fail in my Jac entry script?

A file run directly with `jac run` is a top-level script, so `import from ..lib { helper }` fails with no known parent package. Use relative imports only between package modules and absolute imports from the entry script.