Python NEC2++ Module
This module wraps the C++ API for antenna simulation of nec2++. It is easier to work with, and more powerful than the C-style API wrapper. Requires Python 3.9+.
Usage
Here is an example that plots a radiation pattern.
from PyNEC import *
import numpy as np
#creation of a nec context
context=nec_context()
#get the associated geometry
geo = context.get_geometry()
#add wires to the geometry
geo.wire(0, 36, 0, 0, 0, -0.042, 0.008, 0.017, 0.001, 1.0, 1.0)
context.geometry_complete(0)
context.gn_card(-1, 0, 0, 0, 0, 0, 0, 0)
#add a "ex" card to specify an excitation
context.ex_card(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0)
#add a "fr" card to specify the frequency
context.fr_card(0, 2, 2400.0e6, 100.0e6)
#add a "rp" card to specify radiation pattern sampling parameters and to cause program execution
context.rp_card(0, 91, 1, 0, 5, 0, 0, 0.0, 45.0, 4.0, 2.0, 1.0, 0.0)
#get the radiation_pattern
rp = context.get_radiation_pattern(0)
# Gains are in decibels
gains_db = rp.get_gain()
gains = 10.0**(gains_db / 10.0)
thetas = rp.get_theta_angles() * 3.1415 / 180.0
phis = rp.get_phi_angles() * 3.1415 / 180.0
# Plot stuff
import matplotlib.pyplot as plt
ax = plt.subplot(111, polar=True)
ax.plot(thetas, gains[:,0], color='r', linewidth=3)
ax.grid(True)
ax.set_title("Gain at an elevation of 45 degrees", va='bottom')
plt.savefig('RadiationPattern.png')
plt.show()
Manual Build & install
Requirements
- Swig
- For Windows: C/C++ compilers.
- Git bash (for running build.sh script)
- uv (recommended) or pip + setuptools + numpy + wheel
Note: Download and extract swigwin.zip and add the path to swig.exe to environment.
Then do following:
$ git clone --recursive https://github.com/tmolteno/python-necpp.git
$ cd python-necpp
$ cd PyNEC
$ ./build.sh
$ uv build # Modern, fast build
$ uv pip install . # Or: pip install .
Note: 'sudo' is not required in windows.
Install from PyPI
$ pip install PyNEC
Note: 'sudo' is not required in windows.
Testing
Requirements
-
python package: matplotlib
$ python example/test_rp.py
The example directory contains the following additional examples (that are inspired by excercises from a course on antennas):
- logperiodic_opt.py is an example on how to combine PyNECPP with scipy.optimize to use a genetic algorithm to optimize an antenna for multiple frequency bands at the same time (which I thin is not possible in 4nec2). The resulting gains and VSWR are plotted over the frequency range of interest. This requires scipy >= 0.15.0 due to the usage of scipy.optimize.differential_evolution.
- monopole_realistic_ground_plane.py plots the vertical gain pattern of a monopole antenna. Its dimensions are optimized with a local search, and the path through the search space is visualized with a heat map.
- dipole.py does a very simple optimization of a dipole, and plots the VSWR over a given frequency range for different system impedances to file.
Release files for PyNEC 2.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pynec-2.3.4.tar.gz | 1.5 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pynec-2.3.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| pynec-2.3.4-cp314-cp314-macosx_11_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 11.0+ ARM64 | Details |
| pynec-2.3.4-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 | Details |
| pynec-2.3.4-cp313-cp313-macosx_11_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 11.0+ ARM64 | Details |
| pynec-2.3.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| pynec-2.3.4-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
| pynec-2.3.4-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| pynec-2.3.4-cp311-cp311-macosx_11_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 11.0+ ARM64 | Details |
Total release size: 24.3 MB
Release files / pynec-2.3.4.tar.gz
| Download URL | pynec-2.3.4.tar.gz |
|---|---|
| Size | 1.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d448d038d2bcb4265d511b2440a5d5ce26081269a776d45139fb8bf17a475df4
|
|
BLAKE2b-256 checksum How to use checksums |
7d266cd71a6769f254cdd52054620b1f9a86d1aa24ec7e48c2668ab886a5fb15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / pynec-2.3.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pynec-2.3.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
99618cecac6488f196c5ea1af175671068563a11507701e7ee966ee5ae48b9fa
|
|
BLAKE2b-256 checksum How to use checksums |
1eb09d67bcf24ed21043158057c7f6b5e46a3ce3568e2fa06a127919a7b55eb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / pynec-2.3.4-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | pynec-2.3.4-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 296.0 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f0979d46b3d82d167663b6623af948990e3c55c7ae24bd59ee2846e8d93efe7b
|
|
BLAKE2b-256 checksum How to use checksums |
f538ef0226bfea17342da286276b2b8d5fa120e384d5f3c1117b5f94e8187902
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / pynec-2.3.4-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pynec-2.3.4-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
a8e732a5814484b2ef12511648fd0e6c38bdfbbd5afa81f816c2ed20cff4509e
|
|
BLAKE2b-256 checksum How to use checksums |
063386f923b75233693a1fbbbebddd377e510e7666f6a26999312f0ac8d133f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / pynec-2.3.4-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | pynec-2.3.4-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 296.1 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f41e8d2846cc0807de84469d4be8105f7f401f4e741a28db3feeb9d48f493a92
|
|
BLAKE2b-256 checksum How to use checksums |
1e71898fe224c9d7f9c20e6d3d82b78bc1ad51fb2be23edcac70134a1b8ed78d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / pynec-2.3.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pynec-2.3.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
783046fc32b1db71645f57b1dce8fdfad43fc297b07ce27ebcff017c7c1f8eca
|
|
BLAKE2b-256 checksum How to use checksums |
653c09dec51bf29a56b00ba6a3b4c092d3b5cf064fcb9cc940f23a61aef6fdaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / pynec-2.3.4-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | pynec-2.3.4-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 296.3 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
de0500d6acd83d8d0cff913b4538cd040950a1bea93bda12fc81757bc55023c8
|
|
BLAKE2b-256 checksum How to use checksums |
faf21808dc9590ea210674c7c593197d8268265596a36c7457a58f40011dd12f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / pynec-2.3.4-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pynec-2.3.4-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
d2b5c803e8402a6ca901c2b87659c03218273a6bd763a3eb92167d4adc1db530
|
|
BLAKE2b-256 checksum How to use checksums |
c9641bb1e4948fd461a855b50dc75b5f92f074ea039ad9ed445099c7e4a77190
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency logRelease files / pynec-2.3.4-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | pynec-2.3.4-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 296.2 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5a609923ea4eeaf2d89657e51963143ff5f6724111e07aa250c65de3d1640aa1
|
|
BLAKE2b-256 checksum How to use checksums |
cdd8aebbff33881214fa3bba73b4824e4c6834c0decd6a47e48390ed17b44ac1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.
Transparency log