Skip to main content

pyspark-asn1

PyPI License

PySpark integration for spark-asn1 — a schema-driven Apache Spark data source for reading ASN.1-encoded files (BER, DER, Aligned PER, Unaligned PER, XER) without any code-generation step.

Installation

pip install pyspark-asn1

Quick start

import pyspark_asn1
from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()

# Register the spark-asn1 JAR with the active session
pyspark_asn1.register(spark)

# Read ASN.1-encoded files exactly like any other Spark format
df = (spark.read
      .format("asn1")
      .option("asn1.schema",   "/path/to/schema.asn1")
      .option("asn1.type",     "MyMessage")
      .option("asn1.encoding", "ber")          # ber | der | per-aligned | per-unaligned | xer
      .load("/data/messages/*.ber"))

df.printSchema()
df.show()

Options

Option Default Description
asn1.schema required Path(s) to .asn1 schema files (comma-separated)
asn1.type required Root ASN.1 type name to decode
asn1.encoding ber ber, der, per-aligned, per-unaligned, xer
asn1.per.framing length-prefixed PER framing: length-prefixed, fixed-length, hex-lines
asn1.per.record.bytes — Record size for fixed-length PER framing
asn1.choice.tag.field _tag Discriminator field name for CHOICE types
asn1.enumerated.as.int false Return ENUMERATED as integer instead of name

CHOICE types

ASN.1 CHOICE maps to a struct with a _tag discriminator plus one nullable field per alternative:

# CHOICE { circle Circle, rectangle Rectangle }
# → schema: _tag STRING, circle STRUCT<…>, rectangle STRUCT<…>

from pyspark.sql.functions import col, when

df.filter(col("_tag") == "circle").select(col("circle.*")).show()

df.select(
    when(col("_tag") == "circle",    col("circle.radius"))
    .when(col("_tag") == "rectangle", col("rectangle.width"))
    .alias("dimension")
).show()

Parallel reads (BER/DER)

Pre-scan a file once to enable parallel Spark tasks:

# Run once — writes a sidecar .asn1idx file
from py4j.java_gateway import java_import
java_import(spark._jvm, "io.github.sparkasn1.spark.asn1.util.Asn1Indexer")
java_import(spark._jvm, "org.apache.hadoop.fs.Path")

Asn1Indexer = spark._jvm.io.github.sparkasn1.spark.asn1.util.Asn1Indexer
path = spark._jvm.org.apache.hadoop.fs.Path("/data/messages.ber")
Asn1Indexer.buildIndex(path, spark._jsc.hadoopConfiguration())

# Subsequent reads are fully parallel
df = spark.read.format("asn1").option("asn1.schema", "schema.asn1") \
    .option("asn1.type", "MyMessage").load("/data/messages.ber")

Metadata

Release files for pyspark-asn1 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyspark-asn1 0.5.1
File Size Uploaded Provenance Actions
pyspark_asn1-0.5.1.tar.gz 12.1 MB Without provenance Details for pyspark_asn1-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyspark-asn1 0.5.1
File Interpreter ABI Platform Actions
pyspark_asn1-0.5.1-py3-none-any.whl Python 3 none any Details for pyspark_asn1-0.5.1-py3-none-any.whl

Total release size: 24.3 MB

Release files / pyspark_asn1-0.5.1.tar.gz

Download URL pyspark_asn1-0.5.1.tar.gz
Size 12.1 MB
Tags Source
SHA-256 checksum
How to use checksums
8ab8bef3c7bd9dc05d2d2719866c7aec0a0c01cca06ad393dcf5a8c2031bf564
BLAKE2b-256 checksum
How to use checksums
c1594e4bc47225a7f74d770067b5558793685dd99b01d4b6c7de06aa4a260583
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / pyspark_asn1-0.5.1-py3-none-any.whl

Download URL pyspark_asn1-0.5.1-py3-none-any.whl
Size 12.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
98cae549c1b8c61ff241c3de34d3c7a4d509f17de597863cd45763d2a1606710
BLAKE2b-256 checksum
How to use checksums
4ddeb93226e89ea36f071bc6dfdd4a8d9164f0209fe18cf3313a1dda5f06680a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for pyspark-asn1 0.5.1

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.

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files No provenance

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