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.2.tar.gz (3.8 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.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: feature_schema-0.1.2.tar.gz
  • Upload date:
  • Size: 3.8 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.2.tar.gz
Algorithm Hash digest
SHA256 eb24a63439b8f5e3c07a689d2173b45b846f569e809ab302a47710aee1346171
MD5 05f84b057e5743e2a9d6d746a890c82d
BLAKE2b-256 6b4335bf456bdca19845920a9a78fb6ce2467a7cf1d5a11880e53a5e44e6359a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: feature_schema-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 46a6a368aff3a3865948bbf8d54c617f0406c4a23bd9127ed12dcb40a7fffe2b
MD5 8c3507adeec5f3990b17420fbeb75743
BLAKE2b-256 3e7a7248082a5125fdb65199e6c04dea4a32cfc49b5cf8ebd78321c52238f0bc

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