model-schema-exporter


Namemodel-schema-exporter JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/hopeatina/model-schema-exporter
SummaryA tool to export model schemas from Django, SQLAlchemy, and FastAPI to JSON
upload_time2024-08-07 21:10:40
maintainerNone
docs_urlNone
authorHope Atina
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Model Schema Exporter

Model Schema Exporter is a versatile Python tool that extracts model schemas from Django, Flask, and FastAPI applications and exports them to JSON format. This tool is particularly useful for developers who need to visualize their data models or integrate them with other tools.

## Installation

You can install Model Schema Exporter using pip:

```bash
pip install model-schema-exporter
```

## Usage

Model Schema Exporter can be used as a command-line tool:

```bash
model-schema-exporter <framework> <output_file> [OPTIONS]
```

- `<framework>`: The web framework you're using. Choose from 'django', 'flask', or 'fastapi'.
- `<output_file>`: The path where the output JSON file will be saved.

### Options

- `--app-label`: (Django only) Specify a particular Django app to extract models from.
- `--project-root PATH`: Specify the root directory of your project. If not provided, the current working directory is used as the default.
- `--verbose`: Enable verbose logging for more detailed output.

### Examples

1. For a Django project (all apps):

```bash
model-schema-exporter django output.json --project-root /path/to/your/project
```

2. For a Django project (specific app):

```bash
model-schema-exporter django output.json --app-label myapp --project-root /path/to/your/project
```

3. For a Flask project:

```bash
model-schema-exporter flask output.json --project-root /path/to/your/project
```

4. For a FastAPI project:

```bash
model-schema-exporter fastapi output.json --project-root /path/to/your/project
```

## How It Works

Model Schema Exporter uses framework-specific shell scripts to extract model information:

1. `extract_django_models.sh`: Extracts models from Django projects.
2. `extract_flask_models.sh`: Extracts models from Flask projects using SQLAlchemy.
3. `extract_fastapi_models.sh`: Extracts Pydantic models from FastAPI projects.

These scripts are executed in the context of your project, ensuring that all project-specific configurations and environment variables are respected.

## Project Root

The `--project-root` option allows you to specify the root directory of your project. This is crucial for the tool to locate your project files and execute the extraction scripts correctly.

- If not specified, the current working directory is used as the project root.
- The project root is typically:
  - For Django: The directory containing `manage.py`
  - For Flask/FastAPI: The directory containing your main application file (e.g., `app.py` or `main.py`)

## Output Format

The tool generates a JSON file with the following structure:

```json
{
  "models": [
    {
      "name": "ModelName",
      "fields": [
        {
          "name": "field_name",
          "type": "FieldType",
          "nullable": true,
          "unique": false
        }
        // ... more fields
      ]
    }
    // ... more models
  ]
}
```

## Framework-specific Notes

### Django

- Ensure your Django settings are properly configured.
- You can extract models from all apps or specify a particular app using the `--app-label` option.

### Flask

- Make sure your models are defined using SQLAlchemy and are importable from your main application file.

### FastAPI

- Ensure your Pydantic models are importable from your main application file.

## Troubleshooting

If you encounter issues:

1. Ensure you're running the command from your project's root directory, or use the `--project-root` option.
2. Check that your project's virtual environment is activated.
3. For Django projects, make sure your `DJANGO_SETTINGS_MODULE` environment variable is correctly set.
4. Run the exporter with the `--verbose` flag for more detailed logging:

```bash
model-schema-exporter django output.json --project-root /path/to/your/project --verbose
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hopeatina/model-schema-exporter",
    "name": "model-schema-exporter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Hope Atina",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/18/73/31d8c4752201f47b39b36af8fdcd5634eabfdff44b0836f9c921338557f4/model-schema-exporter-0.1.3.tar.gz",
    "platform": null,
    "description": "# Model Schema Exporter\n\nModel Schema Exporter is a versatile Python tool that extracts model schemas from Django, Flask, and FastAPI applications and exports them to JSON format. This tool is particularly useful for developers who need to visualize their data models or integrate them with other tools.\n\n## Installation\n\nYou can install Model Schema Exporter using pip:\n\n```bash\npip install model-schema-exporter\n```\n\n## Usage\n\nModel Schema Exporter can be used as a command-line tool:\n\n```bash\nmodel-schema-exporter <framework> <output_file> [OPTIONS]\n```\n\n- `<framework>`: The web framework you're using. Choose from 'django', 'flask', or 'fastapi'.\n- `<output_file>`: The path where the output JSON file will be saved.\n\n### Options\n\n- `--app-label`: (Django only) Specify a particular Django app to extract models from.\n- `--project-root PATH`: Specify the root directory of your project. If not provided, the current working directory is used as the default.\n- `--verbose`: Enable verbose logging for more detailed output.\n\n### Examples\n\n1. For a Django project (all apps):\n\n```bash\nmodel-schema-exporter django output.json --project-root /path/to/your/project\n```\n\n2. For a Django project (specific app):\n\n```bash\nmodel-schema-exporter django output.json --app-label myapp --project-root /path/to/your/project\n```\n\n3. For a Flask project:\n\n```bash\nmodel-schema-exporter flask output.json --project-root /path/to/your/project\n```\n\n4. For a FastAPI project:\n\n```bash\nmodel-schema-exporter fastapi output.json --project-root /path/to/your/project\n```\n\n## How It Works\n\nModel Schema Exporter uses framework-specific shell scripts to extract model information:\n\n1. `extract_django_models.sh`: Extracts models from Django projects.\n2. `extract_flask_models.sh`: Extracts models from Flask projects using SQLAlchemy.\n3. `extract_fastapi_models.sh`: Extracts Pydantic models from FastAPI projects.\n\nThese scripts are executed in the context of your project, ensuring that all project-specific configurations and environment variables are respected.\n\n## Project Root\n\nThe `--project-root` option allows you to specify the root directory of your project. This is crucial for the tool to locate your project files and execute the extraction scripts correctly.\n\n- If not specified, the current working directory is used as the project root.\n- The project root is typically:\n  - For Django: The directory containing `manage.py`\n  - For Flask/FastAPI: The directory containing your main application file (e.g., `app.py` or `main.py`)\n\n## Output Format\n\nThe tool generates a JSON file with the following structure:\n\n```json\n{\n  \"models\": [\n    {\n      \"name\": \"ModelName\",\n      \"fields\": [\n        {\n          \"name\": \"field_name\",\n          \"type\": \"FieldType\",\n          \"nullable\": true,\n          \"unique\": false\n        }\n        // ... more fields\n      ]\n    }\n    // ... more models\n  ]\n}\n```\n\n## Framework-specific Notes\n\n### Django\n\n- Ensure your Django settings are properly configured.\n- You can extract models from all apps or specify a particular app using the `--app-label` option.\n\n### Flask\n\n- Make sure your models are defined using SQLAlchemy and are importable from your main application file.\n\n### FastAPI\n\n- Ensure your Pydantic models are importable from your main application file.\n\n## Troubleshooting\n\nIf you encounter issues:\n\n1. Ensure you're running the command from your project's root directory, or use the `--project-root` option.\n2. Check that your project's virtual environment is activated.\n3. For Django projects, make sure your `DJANGO_SETTINGS_MODULE` environment variable is correctly set.\n4. Run the exporter with the `--verbose` flag for more detailed logging:\n\n```bash\nmodel-schema-exporter django output.json --project-root /path/to/your/project --verbose\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License.\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A tool to export model schemas from Django, SQLAlchemy, and FastAPI to JSON",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/hopeatina/model-schema-exporter"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75858cebf6b8f3e5148e8755841648d820703628dd2c7cf3ca27b648106bbe4f",
                "md5": "795663b356e93bc22818bd2c56dab882",
                "sha256": "7f7d86533dee94b14dfb94326d70cc75d64dde227910929185ea5efc709c9132"
            },
            "downloads": -1,
            "filename": "model_schema_exporter-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "795663b356e93bc22818bd2c56dab882",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8230,
            "upload_time": "2024-08-07T21:10:29",
            "upload_time_iso_8601": "2024-08-07T21:10:29.940058Z",
            "url": "https://files.pythonhosted.org/packages/75/85/8cebf6b8f3e5148e8755841648d820703628dd2c7cf3ca27b648106bbe4f/model_schema_exporter-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "187331d8c4752201f47b39b36af8fdcd5634eabfdff44b0836f9c921338557f4",
                "md5": "32c0569800c97f0a0ee32a9c68232d0a",
                "sha256": "89b27e8d2465e461e78ad00cea2214be48ae239c9e0e8f59799c477b5583e28c"
            },
            "downloads": -1,
            "filename": "model-schema-exporter-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "32c0569800c97f0a0ee32a9c68232d0a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5838,
            "upload_time": "2024-08-07T21:10:40",
            "upload_time_iso_8601": "2024-08-07T21:10:40.971719Z",
            "url": "https://files.pythonhosted.org/packages/18/73/31d8c4752201f47b39b36af8fdcd5634eabfdff44b0836f9c921338557f4/model-schema-exporter-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-07 21:10:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hopeatina",
    "github_project": "model-schema-exporter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "model-schema-exporter"
}
        
Elapsed time: 0.33332s