Skip to main content

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.

Metadata

Release files for PyNEC 2.4.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 PyNEC 2.4.0
File Size Uploaded Provenance Actions
pynec-2.4.0.tar.gz 1.5 MB With provenance Details for pynec-2.4.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for PyNEC 2.4.0
File Actions
pynec-2.4.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for pynec-2.4.0-cp311-abi3-win_amd64.whl
pynec-2.4.0-cp311-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for pynec-2.4.0-cp311-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
pynec-2.4.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for pynec-2.4.0-cp311-abi3-macosx_11_0_arm64.whl
pynec-2.4.0-cp311-abi3-macosx_10_9_x86_64.whl CPython 3.11 abi3 macOS 10.9+ x86-64 Details for pynec-2.4.0-cp311-abi3-macosx_10_9_x86_64.whl

Total release size: 8.0 MB

Release files / pynec-2.4.0.tar.gz

Download URL pynec-2.4.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
5412a06d07df7c59bcc80ef2ae8a1d55356f77d74c043cdef329552df43915a4
BLAKE2b-256 checksum
How to use checksums
86a30a230066f11e766c11fc470e69e8acb971c09db31e5131887b39a916e082
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 9, 2026.

Transparency log

Release files / pynec-2.4.0-cp311-abi3-win_amd64.whl

Download URL pynec-2.4.0-cp311-abi3-win_amd64.whl
Size 451.9 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
cd17d8ae971dbd6d0c013d68728875dae5b7fc7d0f7bb70c364f22619dfa424f
BLAKE2b-256 checksum
How to use checksums
b3a906512f4d1b612de29c238e8cd3595bd0f4585d77efa7946d2f6d30942c2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 9, 2026.

Transparency log

Release files / pynec-2.4.0-cp311-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pynec-2.4.0-cp311-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
f325721103666407d4d2763b292e80261eda5c3058bfb3641e00ebd06321a7fd
BLAKE2b-256 checksum
How to use checksums
1c43b63ad136e716ae0d1f0268dd89c73ec23801c440f7e7189948f105edce55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 9, 2026.

Transparency log

Release files / pynec-2.4.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL pynec-2.4.0-cp311-abi3-macosx_11_0_arm64.whl
Size 305.5 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
34c9669358799747bbf4ed625ee38579790e8614cf83ab1ef6a13da354a9d38a
BLAKE2b-256 checksum
How to use checksums
43e8056702e3d3810137a3f84b4542cd93d852cf3b08df92405815872d92ef8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 9, 2026.

Transparency log

Release files / pynec-2.4.0-cp311-abi3-macosx_10_9_x86_64.whl

Download URL pynec-2.4.0-cp311-abi3-macosx_10_9_x86_64.whl
Size 331.2 kB
Tags CPython 3.11 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
82911477abf7b69a247ce9f1ddf037ce9aeea428b5ef85574ec5b5946f7a1745
BLAKE2b-256 checksum
How to use checksums
b7a451ec1ff2ef7ef072a5d18f09318eb89bb4f8275dd28abefa3ce88d360610
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 9, 2026.

Transparency log

Security for PyNEC 2.4.0

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.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for pynec-2.4.0.tar.gz

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 Nov 9, 2026.

Transparency log

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.

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