A tool to generate form JSON schemas from prompts
Project description
FormGen
FormGen is a Python tool that helps you quickly generate React form components from JSON schemas. It’s useful for frontend-backend integration workflows, rapid prototyping, or generating boilerplate form code in large projects.
📂 Project Structure
formgen/
├── package/
│ └── react_generator.py
├── test/
│ └── test_react.py
├── sample_schema.json
├── README.md
└── setup.py
Installation
You can install this package locally using:
pip install .
Or, if uploading to PyPI:
pip install formgen
How to Use
1. Prepare a JSON schema
Create a JSON file that defines your form fields and their properties.
Example: sample_schema.json
{
"username": {
"label": "Username",
"type": "text",
"required": true,
"placeholder": "Enter your username"
},
"email": {
"label": "Email Address",
"type": "email",
"required": true
},
"password": {
"label": "Password",
"type": "password",
"required": true
}
}
2. Write your Python script
Use the generate_react_form function to generate your form component.
Example: test/test_react.py
import json
from package.react_generator import generate_react_form
with open("sample_schema.json") as f:
schema = json.load(f)
output_path = "GeneratedForm.jsx"
generate_react_form(schema, output_path)
3. Run the script
python test/test_react.py
After running, you'll get a GeneratedForm.jsx file containing a full React form component.
🧪 Output
The generated JSX form will look like this (simplified):
import { useState } from 'react';
export default function Form() {
const [username, setUsername] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const handleSubmit = (e) => {
e.preventDefault();
console.log({ username, email, password });
};
return (
<form onSubmit={handleSubmit}>
<div>
<label>Username</label>
<input
name="username"
value={username}
onChange={(e) => setUsername(e.target.value)}
required
placeholder="Enter your username"
type="text"
/>
</div>
...
<button type="submit">Submit</button>
</form>
);
}
Field Attributes Supported
Each field can have:
label: The label shown beside the inputtype: Input type (text, email, password, etc.)required: Boolean to mark required fieldsplaceholder: Placeholder text
🛠 Development
Clone the repository and install locally:
git clone https://github.com/yourusername/formgen.git
cd formgen
pip install -e .
You can add tests in the test/ directory and schemas in JSON format to test new features.
📦 Publishing to PyPI
To publish this package:
- Install Twine:
pip install twine
- Build distribution:
python setup.py sdist bdist_wheel
- Upload to PyPI:
twine upload dist/*
License
MIT License. See LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyformgen-0.1.0.tar.gz.
File metadata
- Download URL: pyformgen-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ae63680cd48cdf3b974394def77e6da4eb8c76a00b45fba982d2ecbd44e2f1b
|
|
| MD5 |
2057b18ba5eb03e2c7a9d2d6f98ddf6f
|
|
| BLAKE2b-256 |
c70c503351e641903c53d568f7de3edfe10f6c2c7634da4b78463058b44fa4c2
|
File details
Details for the file pyformgen-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyformgen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
faec3ad37038d85276f937aeed0a54187a56ee0e75a602a1e79f223766997ab2
|
|
| MD5 |
3d7ca71689400c2fff4fff0067ffc985
|
|
| BLAKE2b-256 |
7a1834487e8b8d51d16619dbda987c3e873f4e46f10daddc8a356685a6296c14
|