api-to-pydantic-utils


Nameapi-to-pydantic-utils JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryUtilities for JSON schema extraction and Pydantic model generation
upload_time2025-08-01 14:34:10
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords pydantic json schema api validation type-hints
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # API to Pydantic Utils

> Core utilities for JSON schema extraction and Pydantic model generation

A Python package that provides utilities for processing JSON data and extracting schemas for Pydantic model generation. Originally developed as part of the [API to Pydantic](https://github.com/luc-pimentel/api-to-pydantic) project.

## Installation

```bash
pip install api-to-pydantic-utils
```

## Features

- **Schema Extraction**: Intelligent JSON schema extraction with 80-95% compression
- **Type Detection**: Automatic detection of emails, URLs, timestamps, and other patterns
- **Model Testing**: Utilities for validating Pydantic models against JSON data
- **JSON Validation**: Simple JSON file validation utilities

## Quick Start

```python
from api_to_pydantic_utils import extract_schema, validate_json_file, create_test_file

# Extract schema from JSON data
schema = extract_schema({"name": "John", "email": "john@example.com"})
print(schema)

# Validate a JSON file
is_valid = validate_json_file("data.json")

# Create test file for a Pydantic model
test_file = create_test_file("model.py", "test_data.json")
```

## API Reference

### `extract_schema(data, max_depth=10)`
Extracts a compressed schema from JSON data.

**Parameters:**
- `data`: JSON data (dict, list, or primitive)
- `max_depth`: Maximum nesting depth to process

**Returns:** Compressed schema representation

### `process_json_file(file_path, max_depth=10)`
Processes a JSON file and extracts its schema.

**Parameters:**
- `file_path`: Path to JSON file
- `max_depth`: Maximum nesting depth to process

**Returns:** Tuple of (schema, compression_stats)

### `validate_json_file(file_path)`
Validates if a file contains valid JSON.

**Parameters:**
- `file_path`: Path to JSON file

**Returns:** Boolean indicating if file is valid JSON

### `create_test_file(model_file_path, json_file_path)`
Creates a test file for validating Pydantic models.

**Parameters:**
- `model_file_path`: Path to Python file with Pydantic model
- `json_file_path`: Path to JSON file to test against

**Returns:** Path to created test file

## Type Detection

The package automatically detects various data patterns:

- **Email addresses**: `john@example.com` → `EmailStr`
- **URLs**: `https://example.com` → `HttpUrl`
- **Timestamps**: `2023-01-01T00:00:00Z` → `datetime`
- **YouTube IDs**: Channel and video ID patterns
- **Usernames**: `@username` patterns
- **Text content**: Long text with punctuation

## Requirements

- Python 3.8+
- Pydantic 2.0+

## License

MIT License

## Contributing

This package is part of the [API to Pydantic](https://github.com/luc-pimentel/api-to-pydantic) project. Please report issues and contribute there.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "api-to-pydantic-utils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Lucas Pimentel <lucas_cpimentel@proton.me>",
    "keywords": "pydantic, json, schema, api, validation, type-hints",
    "author": null,
    "author_email": "Lucas Pimentel <lucas_cpimentel@proton.me>",
    "download_url": "https://files.pythonhosted.org/packages/83/a0/bf69b494272ef383a91564eeb6b9e15563687001fd02fdd55250b47e4443/api_to_pydantic_utils-0.1.1.tar.gz",
    "platform": null,
    "description": "# API to Pydantic Utils\r\n\r\n> Core utilities for JSON schema extraction and Pydantic model generation\r\n\r\nA Python package that provides utilities for processing JSON data and extracting schemas for Pydantic model generation. Originally developed as part of the [API to Pydantic](https://github.com/luc-pimentel/api-to-pydantic) project.\r\n\r\n## Installation\r\n\r\n```bash\r\npip install api-to-pydantic-utils\r\n```\r\n\r\n## Features\r\n\r\n- **Schema Extraction**: Intelligent JSON schema extraction with 80-95% compression\r\n- **Type Detection**: Automatic detection of emails, URLs, timestamps, and other patterns\r\n- **Model Testing**: Utilities for validating Pydantic models against JSON data\r\n- **JSON Validation**: Simple JSON file validation utilities\r\n\r\n## Quick Start\r\n\r\n```python\r\nfrom api_to_pydantic_utils import extract_schema, validate_json_file, create_test_file\r\n\r\n# Extract schema from JSON data\r\nschema = extract_schema({\"name\": \"John\", \"email\": \"john@example.com\"})\r\nprint(schema)\r\n\r\n# Validate a JSON file\r\nis_valid = validate_json_file(\"data.json\")\r\n\r\n# Create test file for a Pydantic model\r\ntest_file = create_test_file(\"model.py\", \"test_data.json\")\r\n```\r\n\r\n## API Reference\r\n\r\n### `extract_schema(data, max_depth=10)`\r\nExtracts a compressed schema from JSON data.\r\n\r\n**Parameters:**\r\n- `data`: JSON data (dict, list, or primitive)\r\n- `max_depth`: Maximum nesting depth to process\r\n\r\n**Returns:** Compressed schema representation\r\n\r\n### `process_json_file(file_path, max_depth=10)`\r\nProcesses a JSON file and extracts its schema.\r\n\r\n**Parameters:**\r\n- `file_path`: Path to JSON file\r\n- `max_depth`: Maximum nesting depth to process\r\n\r\n**Returns:** Tuple of (schema, compression_stats)\r\n\r\n### `validate_json_file(file_path)`\r\nValidates if a file contains valid JSON.\r\n\r\n**Parameters:**\r\n- `file_path`: Path to JSON file\r\n\r\n**Returns:** Boolean indicating if file is valid JSON\r\n\r\n### `create_test_file(model_file_path, json_file_path)`\r\nCreates a test file for validating Pydantic models.\r\n\r\n**Parameters:**\r\n- `model_file_path`: Path to Python file with Pydantic model\r\n- `json_file_path`: Path to JSON file to test against\r\n\r\n**Returns:** Path to created test file\r\n\r\n## Type Detection\r\n\r\nThe package automatically detects various data patterns:\r\n\r\n- **Email addresses**: `john@example.com` \u2192 `EmailStr`\r\n- **URLs**: `https://example.com` \u2192 `HttpUrl`\r\n- **Timestamps**: `2023-01-01T00:00:00Z` \u2192 `datetime`\r\n- **YouTube IDs**: Channel and video ID patterns\r\n- **Usernames**: `@username` patterns\r\n- **Text content**: Long text with punctuation\r\n\r\n## Requirements\r\n\r\n- Python 3.8+\r\n- Pydantic 2.0+\r\n\r\n## License\r\n\r\nMIT License\r\n\r\n## Contributing\r\n\r\nThis package is part of the [API to Pydantic](https://github.com/luc-pimentel/api-to-pydantic) project. Please report issues and contribute there.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Utilities for JSON schema extraction and Pydantic model generation",
    "version": "0.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/luc-pimentel/api-to-pydantic/issues",
        "Documentation": "https://github.com/luc-pimentel/api-to-pydantic#readme",
        "Homepage": "https://github.com/luc-pimentel/api-to-pydantic",
        "Repository": "https://github.com/luc-pimentel/api-to-pydantic"
    },
    "split_keywords": [
        "pydantic",
        " json",
        " schema",
        " api",
        " validation",
        " type-hints"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "381877314d8bf5f16518a172cf97ca007f3a2f9289f4bc9ef5282ca467f84b3c",
                "md5": "5de0c75ae762b5587f839136d50d2cd0",
                "sha256": "22d17af20cbab6f2503481be82c8aed32b2a20f4c36e35c2ceb86c7a7e9d4cf5"
            },
            "downloads": -1,
            "filename": "api_to_pydantic_utils-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5de0c75ae762b5587f839136d50d2cd0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9421,
            "upload_time": "2025-08-01T14:34:09",
            "upload_time_iso_8601": "2025-08-01T14:34:09.197631Z",
            "url": "https://files.pythonhosted.org/packages/38/18/77314d8bf5f16518a172cf97ca007f3a2f9289f4bc9ef5282ca467f84b3c/api_to_pydantic_utils-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "83a0bf69b494272ef383a91564eeb6b9e15563687001fd02fdd55250b47e4443",
                "md5": "fa75c52817b17f9a69607a548945112f",
                "sha256": "dedccb9ae7eba817254404fcc37af6a30bef3ebb9f9abdbee0c128a281181bc1"
            },
            "downloads": -1,
            "filename": "api_to_pydantic_utils-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "fa75c52817b17f9a69607a548945112f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9908,
            "upload_time": "2025-08-01T14:34:10",
            "upload_time_iso_8601": "2025-08-01T14:34:10.701458Z",
            "url": "https://files.pythonhosted.org/packages/83/a0/bf69b494272ef383a91564eeb6b9e15563687001fd02fdd55250b47e4443/api_to_pydantic_utils-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-01 14:34:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "luc-pimentel",
    "github_project": "api-to-pydantic",
    "github_not_found": true,
    "lcname": "api-to-pydantic-utils"
}
        
Elapsed time: 3.36230s