Skip to main content

A lightweight package to extract, document, and validate feature schemas from pandas DataFrames for ML workflows.

Project description

feature_schema

feature_schema is a lightweight Python package that automatically extracts and documents feature metadata from a pandas DataFrame.
It’s designed for machine learning workflows where you need to understand, validate, or dynamically generate user inputs for model features.


Features

  • Extract feature name
  • Auto-detect feature types (int, float, string, bool, datetime)
  • Numeric metadata: min, max, range
  • Categorical metadata: unique values & counts
  • Nullability check: detect if features contain missing values
  • Human-readable docs (__str__) for quick schema inspection
  • Exportable schema to dict / DataFrame for further use

Installation

pip install feature_schema

Usage

1. Create the Schema for a DataFrame

import pandas as pd
from feature_schema import FeatureSchema

# Sample dataset
df = pd.DataFrame({
    "age": [25, 30, 40, 22],
    "salary": [50000.0, 60000.5, 80000.2, 45000.0],
    "city": ["NY", "SF", "LA", "NY"]
})

# Create Feature schema object
fs = FeatureSchema(df)

# Print schema (human readable)
print(fs.to_dict())

Output:

[
    {'column_name': 'age', 'dtype': 'int64', 'type': 'int', 'nullable': np.False_, 'min': 22.0, 'max': 40.0, 'unique_values': 4}, {'column_name': 'salary', 'dtype': 'float64', 'type': 'float', 'nullable': np.False_, 'min': 45000.0, 'max': 80000.2, 'unique_values': 4}, {'column_name': 'city', 'dtype': 'object', 'type': 'string', 'nullable': np.False_, 'unique_values': 3, 'unique_list': ['NY', 'SF', 'LA']}
]

2. Export Schema as Dictionary / DataFrame

# As dictionary
schema_dict = fs.to_dict()
print(schema_dict)

# As DataFrame
schema_df = fs.to_dataframe()
print(schema_df)

Why Use feature_schema?

  • No more hardcoding feature names, types, and ranges
  • Auto-generate Streamlit forms or FastAPI validation schemas
  • Save schema along with ML models for reproducibility
  • Helps teams document datasets automatically
  • Helps to validate input

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

feature_schema-0.1.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

feature_schema-0.1.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file feature_schema-0.1.3.tar.gz.

File metadata

  • Download URL: feature_schema-0.1.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for feature_schema-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ff781266d3167e1f2e5e685478138b6defb85e2f2cd6ad8f01cd4f22266eed48
MD5 4a569ed664068707aed705dcd5895aad
BLAKE2b-256 4d1c164088a294e31b5cb0916ac94906083e952c6296b07975e84f34e28b228e

See more details on using hashes here.

File details

Details for the file feature_schema-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: feature_schema-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for feature_schema-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ee491d2467e4e3c1f6df206d2f0311aefca1d7e9a2259d0443e9f3d73ccef460
MD5 2337661b019e0374f4c966395a6b43c4
BLAKE2b-256 9c1f33181b7c36d9ebb0884c47a79cc8ca4cfe3331e37c3766627519421d78d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page