Skip to main content

Mongo Schema

Reverse engineer JSONSchemas from a MongoDB database.

Installation

pip install mongo-jsonschema

Usage

As CLI Tool

usage: python -m mongo_jsonschema [-h] [-c COLLECTIONS] [-p PORT] [-s SAMPLE_SIZE] [-r {PRIMARY,PRIMARY_PREFERRED,SECONDARY,SECONDARY_PREFERRED,NEAREST}] [-d DESTINATION] [-e] host db

Generates JSONSchemas from MongoDB Collections by sampling documents from the collection.

positional arguments:
  host                  A MongoDB hostname or connection string.
  db                    The name of the database in which the collections reside.

optional arguments:
  -h, --help            show this help message and exit
  -c COLLECTIONS, --collections COLLECTIONS
                        A comma separated list of collections to generate schemas from. If blank, schemas will be generated for all collections.
  -p PORT, --port PORT  The port to use when connecting to the MongoDB server. Required if host is not a connectionstring.
  -s SAMPLE_SIZE, --sample_size SAMPLE_SIZE
                        A decimal representation of the percentage of total documents in the collection to sample when deriving the schema. Default is .33.
  -r {PRIMARY,PRIMARY_PREFERRED,SECONDARY,SECONDARY_PREFERRED,NEAREST}, --read_preference {PRIMARY,PRIMARY_PREFERRED,SECONDARY,SECONDARY_PREFERRED,NEAREST}
                        The read preference to use when querying the MongoDB database. Default is 'SECONDARY'.
  -d DESTINATION, --destination DESTINATION
                        The directory to output the generated schemas to. If none is specified, will be output to the current working directory.
  -e, --external_sorting
                        Enables external sorting, using the disk on the mongodb server, for aggregations that exceed the memory limit. If false, the aggregation fails due to an exceeded memory limit, the
                        schema will be skipped.

As A Library

from mongo_jsonschema import SchemaGenerator

# Initialize with your mongodb hostname and port
schema_generator = SchemaGenerator('localhost', 27017)
# Or use a connection string
schema_generator = SchemaGenerator('mongodb+srv://username:password@localhost/mydatabase')

#Generate schema for a multiple collections
schemas = schema_generator.get_schemas(
    db='mydatabase', 
    collections=['foo','bar'],
    sample_percent=.05
)

# Generate schema for a single collection.
schema = schema_generator.get_schemas(
    db='dbname',
    collection='baz',
    sample_percent=.05
)

Metadata

Release files for mongo-jsonschema 0.1.4

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

Source distribution (sdist)

Source distribution for mongo-jsonschema 0.1.4
File Size Uploaded Provenance Actions
mongo_jsonschema-0.1.4.tar.gz 4.5 kB Without provenance Details for mongo_jsonschema-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mongo-jsonschema 0.1.4
File Interpreter ABI Platform Actions
mongo_jsonschema-0.1.4-py3-none-any.whl Python 3 none any Details for mongo_jsonschema-0.1.4-py3-none-any.whl

Total release size: 10.3 kB

Release files / mongo_jsonschema-0.1.4.tar.gz

Download URL mongo_jsonschema-0.1.4.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4d3bb6a016936d4cc4f31c5d4fbcc126e546761105d00c3ccadaee768e9d86d4
BLAKE2b-256 checksum
How to use checksums
85736be26af3f0df23fcaeaaa1c7e603c4a1d1a830dd1c8d268b969abbd9551c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.6 Darwin/23.3.0

Release files / mongo_jsonschema-0.1.4-py3-none-any.whl

Download URL mongo_jsonschema-0.1.4-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d36c85f38d18029db7f023df5b719b427500e8439d1afee318565a68ea2fa53
BLAKE2b-256 checksum
How to use checksums
83c29ee7852e8b7b2deb980757fdd77448c89064fa237535cdea3bc23d0ac50f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.6 Darwin/23.3.0

Security for mongo-jsonschema 0.1.4

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.

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