OSCAR's optional wheel provides OscarCodec, a typed class using JPype1 to
invoke the bundled Java engine in one embedded JVM. It requires standard
CPython 3.10+ and a matching 64-bit Java 21+ runtime. The wheel includes the
shaded engine JAR and Java dependency notices. JPype1 is a separate Python runtime
dependency; its transitive dependency is packaging. No Maven, Java compiler,
C/C++ compiler or source checkout is required when compatible binary wheels exist.
The package never downloads Java. Ordinary Maven builds remain Python-independent.
Download the OSCAR wheel and SHA-256 sidecar from the matching GitHub release
when available. A local candidate/version does not establish publication. OSCAR
is not published to PyPI by this workflow. Verify the sidecar before installing:
sha256sum -c <wheel>.sha256 on Ubuntu, shasum -a 256 -c <wheel>.sha256 on macOS,
or compare PowerShell Get-FileHash <wheel> -Algorithm SHA256 with the sidecar.
Ubuntu and macOS, after separately installing Java 21 and compatible CPython:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install --only-binary=:all: ./oscar-<version>-py3-none-any.whl
java -version
python -c 'from oscar import ConfigType, OscarCodec; print(OscarCodec(ConfigType.DOCSIS_3_1).encode("Docsis { NetworkAccess 1; }").hex())'The last command prints 030101, a TLV fragment, and verifies actual embedded
Java invocation. Ubuntu may require the python3-venv OS package. The repository's
--development setup handles that prerequisite; wheel users need only a JRE.
Windows PowerShell, using x64 Python with an x64 Java runtime:
py -3 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --only-binary=:all: .\oscar-<version>-py3-none-any.whl
java -version
python -c "from oscar import ConfigType, OscarCodec; print(OscarCodec(ConfigType.DOCSIS_3_1).encode('Docsis { NetworkAccess 1; }').hex())"Use native ARM64 Python and Java together on Apple Silicon, or x64 versions of both under an emulated environment. Windows ARM-hosted CI selects x64 Python and Java; that does not establish native Windows ARM64 support. Linux x64/ARM64, macOS universal2 and Windows x64 dependency wheels were verified available for the pinned acceptance versions. Actual nonlocal runtime validation remains pending. Free-threaded interpreters and platforms without a compatible JPype wheel are outside the accepted scope; binary-only installation fails instead of compiling.
The dependency policy is JPype1>=1.7.1,<1.8, with acceptance pinned to 1.7.1 and
packaging 26.4 in python/runtime-requirements.txt. Review a new JPype minor series
before changing the bound. Upgrades use the same binary-only option:
python -m pip install --only-binary=:all: --upgrade ./oscar-<new-version>-py3-none-any.whl
python -m pip checkUninstall with python -m pip uninstall oscar; remove the virtual environment
when no longer needed. These commands do not install, upgrade or remove Java.
On a networked machine with the same Python/OS/architecture as the destination, prepare the JPype and packaging wheelhouse separately:
python -m pip download --only-binary=:all: --dest wheelhouse 'JPype1==1.7.1' 'packaging==26.4'Transfer that directory, the OSCAR wheel and verified checksum, then install:
python -m pip install --no-index --find-links wheelhouse --only-binary=:all: ./oscar-<version>-py3-none-any.whl
python -m pip checkThe OSCAR wheel remains py3-none-any: it contains Python and portable Java
artifacts. JPype's native platform wheel is resolved separately, never embedded
or compiled by OSCAR.
from oscar import ConfigType, OscarCodec
codec = OscarCodec(ConfigType.DOCSIS_3_1)
text = """Docsis {
NetworkAccess 1;
UpstreamServiceFlow { ServiceFlowReference 1; QualityOfServiceParameterSetType 07; }
DownstreamServiceFlow { ServiceFlowReference 2; QualityOfServiceParameterSetType 07; }
}"""
binary = codec.encode(text, shared_secret="public-example-key")
restored = codec.decode(binary)
assert codec.encode(restored, shared_secret="public-example-key") == binaryPublic signatures:
OscarCodec(config_type: ConfigType | None = None)
codec.encode(config_text: str, *, shared_secret: str | None = None) -> bytes
codec.decode(config_data: bytes) -> str
codec.encode_file(input_file: str | Path, output_file: str | Path, *,
shared_secret: str | None = None, overwrite: bool = False) -> Path
codec.decode_file(input_file: str | Path, output_file: str | Path, *,
overwrite: bool = False) -> PathAn instance retains only its edition selection, never a shared secret or Java object. Independent instances share one compatible JVM. Results are native, owned Python bytes/str/Path values. The adapter copies input/output in O(n) space/time for n bytes; Java owns configuration processing and its complexity.
Without a secret, encode returns unfinalized imported bytes. This supports
fragments and exact preservation without complete-file requiredness checks or
new integrity fields. A supplied string invokes the existing Java compiler and
commit(). Empty keys fail where Java requires a CMTS key; shared_secret=""
requests existing unkeyed PacketCable/DPoG finalization. Decoding does not
authenticate MICs. Passing tests is not device interoperability or whole-spec
conformance. Non-ASCII SNMP values follow Java's existing hex-text export policy;
UTF-8 bytes and unmodified re-encoding are preserved.
The previous module-level encode/decode/encode_file/decode_file signatures remain
as thin compatibility delegates to OscarCodec. They retain their config_type
keyword. There is one implementation and one production JPype backend.
Use a ConfigType member; primitive string/integer/Boolean selectors fail.
| Family | Members |
|---|---|
| DOCSIS | DOCSIS_1_0, DOCSIS_1_1, DOCSIS_2_0, DOCSIS_3_0, DOCSIS_3_1, DOCSIS_4_0 |
| DPoE | DPOE_1_0, DPOE_2_0 |
| DPoG | DPOG_1_0 |
| PacketCable | PACKETCABLE_1_0, PACKETCABLE_1_5, PACKETCABLE_2_0 |
The mapping is checked against original Java constants. Shared Docsis and DPoE headers do not identify exact editions; provide a ConfigType. None permits only unique Docsis-4.0, DPoG or versioned PacketCable header detection through Java. All binary decoding requires an explicit edition. Header/family conflicts fail.
codec.encode_file("modem.txt", "modem.cm", shared_secret="public-example-key")
codec.decode_file("modem.cm", "decoded.txt")File methods call memory methods. They require UTF-8 text, reject source aliases (including hardlinks) and output symlinks, and refuse existing destinations unless overwrite=True. Restricted sibling output is flushed, fsynced and atomically published. No-clobber publication uses a same-directory hardlink; unsupported filesystems fail explicitly. Processing/publication failures retain existing outputs and clean temporary siblings. Inputs are not edited.
Catch OscarError, or ConfigurationError, EncodeError, DecodeError, JavaRuntimeError and FileOperationError for typed recovery. OscarRuntimeError is a compatibility alias for JavaRuntimeError. Java diagnostics and exceptions are translated to fixed redacted Python errors; no Java objects escape the API. Secrets remain operation arguments and never enter argv or codec attributes. The adapter suppresses diagnostics on its operation thread and preserves other threads, logger levels and Java stdout/stderr streams.
Import and construction do not start Java. First processing lazily initializes one synchronized JVM. All codec operations serialize shared Java state across instances. The library never shuts down or restarts Java. If an application shuts it down, restart the Python process before using the codec again.
Set JAVA_HOME to a Java 21+ runtime. JPype locates the native JVM library, not a java executable subprocess. OSCAR_JVM explicitly selects libjvm.so, jvm.dll or libjvm.dylib; OSCAR_JAR overrides the complete matching engine for development. Unset these for normal wheel use. Architecture checks inspect the native library and the Python process, including x64 Python on Windows ARM hosts. Java must use UTF-8 as its default charset. No configuration-processing Java subprocess runs.
OSCAR_CACHE_DIR optionally chooses an existing parent before first processing. The runtime creates a process-private directory and SNMP cache before Java engine initialization. Instances share this cache; normal process exit removes it. Embedded mode disables the optional host snmptranslate fallback; numeric OIDs and bundled aliases work without host MIB paths or tool processes. Unknown textual OID aliases must be replaced with numeric OIDs. Memory APIs create no intermediate configuration files. Environment choices freeze at first startup. Adapter-owned JVMs use a 256 MiB heap; application-owned JVM heap limits remain application-owned. Payloads are bounded to 4 MiB and secrets to 65,536 Unicode code points. These are adapter policies, not protocol maxima.
OSCAR_JAVA and OSCAR_TIMEOUT_SECONDS are retired and explicitly rejected. Embedded Java has no safe hard timeout, forced cancellation or per-operation heap isolation. Use application-owned spawned processes when those controls are required. JVM injection environment variables must be unset before an adapter-owned start; no global environment or logging configuration is replaced.
For multiprocessing, select multiprocessing.get_context("spawn") and construct
codecs in each worker. Do not fork after JVM startup: inherited state fails before
entering JNI or acquiring an inherited lock. Lazy JVM creation on Python threads
is synchronized; newly owned worker attachments are released after calls. External
Java operations bypassing the facade and host reconfiguration during a call are
outside the serialization guarantee.
Reuse requires Java 21+, matching architecture/UTF-8, the exact complete engine JAR and dependencies from this wheel, and these JVM startup arguments:
-Doscar.python.embedded=true
-Doscar.snmp.cache.path=/absolute/private-directory/oid-cache.json
The directory must exist and be private (0700 on POSIX); keep it alive for the JVM lifetime. Set the properties before engine initialization. Setting them only after startup does not establish compatibility. Conflicting classpath JARs, missing dependencies and incompatible global logging filters are rejected; the wrapper does not add classpaths to or shut down an existing application JVM.
Four executable examples under python/examples cover memory round trips, atomic encoding/decoding files, and explicit DPoE/DPoG/PacketCable profiles. The file examples refuse repeat overwrites; encoding accepts --prompt-secret rather than an argv secret. Follow development setup:
./install.sh --python --development
.venv-python-build/bin/python tools/python/build_wheel.py
.venv-python-build/bin/python tools/python/validate.py --wheel dist/python/oscar-<version>-py3-none-any.whlThe full ./install.sh --development includes this environment plus its existing
Linux host tools and the Python venv prerequisite. Inspection uses --check or
--dry-run with --python. Windows uses .venv-python-build\Scripts\python.exe and
manual environment setup as the Linux host installer is separate.
The wheel builder uses the POM version, shaded JAR and dependency notices without changing Java build procedures. Validation downloads compatible dependency wheels as a separate step, then installs offline into a fresh environment outside the checkout. Supply --offline --wheelhouse DIRECTORY to prohibit the download step.
See test methodology, canonical architecture/UML, requirements, delivery checklist and migration assessment/evidence.
Missing/incompatible Java, wrong native architecture, mixed engine/dependency JARs and startup failures produce JavaRuntimeError. Correct JAVA_HOME/OSCAR_JVM, use a complete wheel and restart Python after failed initialization. Bad editions produce ConfigurationError, parsing/compilation failures EncodeError, and truncated/unsupported or lossy DPoE exports DecodeError. Do not repair text between round-trip iterations. Catalog limitations and deferred protocol fields remain Java-owned. The local accepted scope is reported separately from prepared hosted Ubuntu/Windows/macOS jobs and release publication; workflow files are not runtime or publication evidence.