Nimic
Nimic is a pure Python module that facilitates writing AOT compilable code with a subset of Python (domain specific language). Based on ctypes built-in module, it includes emulation of native types, pointers and operations on them, implementing dispatch, operator overloading, and templates. Nimic closely follows Nim programming language, to which nimic code transpiles.
Key principle: nimic code is valid Python that runs natively and transpiles to equivalent Nim code.
Module Architecture
nimic/
├── ntypes.py — Public API: re-exports type system + Nim keyword/builtin shims
├── ntypesystem.py — Core type system (Object, NScalar, seq, dispatch, distinct, converter)
├── transpiler.py — AST-based Python → Nim source code transpiler
├── inliner.py — Template function inlining (@template, @template_expand)
├── ncode/ — Nim definitions (pydefs.nim, pystd/)
├── std/ — Python shims for Nim stdlib (math, options, os, paths, strformat, ...)
└── system/ — Python shims for Nim system modules (ansi_c)
ntypesystem.py — Core Type System
Organized in layers from low-level memory to high-level abstractions:
| Layer | Classes | Purpose |
|---|---|---|
| Memory | Ntype, NTypeRegistry |
ctypes-backed buffers with value semantics |
| Scalars | NScalar → NInteger / NFloat |
Fixed-width types (int8..int64, uint8..uint64, float16..float64) with arithmetic promotion |
| Structs | Object |
Nim "object" — fields via annotations, backed by ctypes.Structure |
| Enums | NIntEnum |
Nim integer enums with auto-registration |
| Variants | Object + match kind: |
Nim "case object" — discriminated unions |
| Containers | seq[T], UncheckedArray[T] |
Growable sequence and pointer-indexed array |
| Dispatch | @dispatch, DispDict, NMetaClass |
Nim-style multi-dispatch via type annotations |
| Modifiers | @distinct, @converter |
Type distinctness and trivial type conversions |
| Strings | string |
str subclass with Nim-compatible &, %, isEmpty |
ntypes.py — Public API & Keywords
Re-exports all of ntypesystem and adds Nim keyword/builtin emulation:
- Compiler hints —
const,let,var,block,export,alias(no-ops in Python, scoping in Nim) - Reference types —
ref,ptr,mut@(@operator returns identity) - Enum utilities —
NStrEnumwithsucc/pred/ord/nrange/low/high - Cast & memory —
cast[T](x),sizeof(x),addr(x),unsafe_addr(x) - Type aliases —
SomeInteger,SomeFloat,untyped,char,u64,i64,f64 - Iteration —
fields(obj),fields(a, b),countdown(a, b) - Compile-time —
comptime(x),defined(varname),static - Templates —
@template,@template_expand(re-exported frominliner)
transpiler.py — Python → Nim Transpiler
A modified CPython ast.py where _Unparser is extended to emit Nim syntax.
Implements 30+ transformation rules for indentation, type definitions, function
signatures, operators, imports, and control flow.
inliner.py — Template Inlining
@template + @template_expand decorators perform AST-level function inlining
for untyped templates, substituting parameter names with call arguments.
DSL Conventions
Nimic uses Python syntax with specific conventions that have dual meaning — runtime behavior in Python and transpilation semantics for Nim:
| Convention | Example | Purpose |
|---|---|---|
with let/var/const: |
with let: x = vec3(1,2,3) |
Variable declaration scope qualifier |
mut @ annotation |
def f(x: mut @ Vec3): |
Mutable argument (var in Nim) |
{.pragma.} docstring |
"""{.inline.}""" |
Nim pragma (inline, borrow, noSideEffect) |
@dispatch |
@dispatch def f(x: float64): |
Multi-dispatch by argument types |
@distinct |
@distinct class Color(Vec3): |
Distinct type (no implicit conversion) |
@template |
@template def toUV(v): |
Template (inlined at call site) |
@converter |
@converter def toVec3(uv): |
Implicit type converter |
<<= |
dst <<= -src |
Value assignment to mutable variable |
match kind: |
match kind: case K.a: ... |
Variant type definition (case object) |
comptime(expr) |
if comptime(cond): |
Compile-time evaluation (when in Nim) |
fields(obj) |
for f in fields(obj): |
Iterate over object fields |
with export: |
with export: mod1, mod2 |
Re-export modules |
Quick Example
from __future__ import annotations
from nimic.ntypes import *
# Struct definition (Nim object)
class Vec3(Object):
x: float64
y: float64
z: float64
def __add__(self: Vec3, v: Vec3) -> Vec3:
"""{.inline.}"""
result = Vec3()
result.x = self.x + v.x
result.y = self.y + v.y
result.z = self.z + v.z
return result
# Distinct type
@distinct
class Point3(Vec3):
"""{.borrow: `.`.}"""
# Multi-dispatch
@dispatch
def point3(x: float64, y: float64, z: float64) -> Point3:
result = Point3(Vec3())
result.x = x; result.y = y; result.z = z
return result
# Usage
with let:
a = point3(1.0, 2.0, 3.0)
b = point3(4.0, 5.0, 6.0)
c = Vec3(a) + Vec3(b)
Metadata
Release files for nimic 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nimic-0.0.5.tar.gz | 99.2 kB | Without provenance | Details for nimic-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nimic-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for nimic-0.0.5-py3-none-any.whl |
Total release size: 212.0 kB
Release files / nimic-0.0.5.tar.gz
| Download URL | nimic-0.0.5.tar.gz |
|---|---|
| Size | 99.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf049b2db5da985193efb04d1df5adaae706cfc375f473269f18713586af0f96
|
|
BLAKE2b-256 checksum How to use checksums |
42d1f288fa2be196ffb98db347d6090ca96532983dd1397c7beb4d69e443ef02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / nimic-0.0.5-py3-none-any.whl
| Download URL | nimic-0.0.5-py3-none-any.whl |
|---|---|
| Size | 112.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e4e1c1c004d9c7aa20a731556928b1177bd82eee57c62139da268f884e0b8849
|
|
BLAKE2b-256 checksum How to use checksums |
a486b6df7e6a2f9385b97f9730dae83b72f389c9bab3882945ab589a5e2c7493
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for nimic 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.