Skip to main content

Text formatting and validation utilities

Project description

Python Package and FastAPI Demo

This project demonstrates how to create a Python package and use it in a FastAPI application.

📚 Documentation

  • 👋 New to this? Start with QUICK_START.md - Simple 3-step guide
  • 📖 Need detailed steps? See SETUP_GUIDE.md - Complete step-by-step instructions
  • ⚡ Want automation? Use the setup scripts: bash setup.sh then bash start_server.sh

🎯 Important: Understanding the Structure

  • Package (my_feature_package/): This is just code that you INSTALL, not run. NO SERVER NEEDED!
  • FastAPI App (fastapi_app/): This is a web server that you RUN. This is the only server.

Project Structure

creating-package-in-python/
├── my_feature_package/          # The Python package
│   ├── __init__.py
│   ├── text_formatter.py        # Text formatting utilities
│   └── validator.py             # Validation utilities
├── fastapi_app/                 # FastAPI application
│   └── main.py                  # FastAPI app using the package
├── setup.py                     # Package installation file
├── requirements.txt             # FastAPI dependencies
└── README.md                    # This file

Installation Steps

1. Install the Package

First, install the package in development mode:

pip install -e .

This will install my-feature-package so it can be imported in your FastAPI app.

2. Install FastAPI Dependencies

pip install -r requirements.txt

Running the FastAPI Application

Start the FastAPI server:

cd fastapi_app
uvicorn main:app --reload

Or from the root directory:

uvicorn fastapi_app.main:app --reload

The API will be available at: http://localhost:8000

API Documentation

Once the server is running, visit:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

API Endpoints

Text Formatter Endpoints

  • POST /format/title - Convert text to title case
  • POST /format/snake - Convert text to snake_case
  • POST /format/reverse - Reverse the text
  • POST /format/capitalize - Capitalize first letter of each word
  • POST /format/remove-whitespace - Remove all whitespace

Validator Endpoints

  • POST /validate/email - Validate email address
  • POST /validate/phone - Validate phone number
  • POST /validate/password - Validate strong password

Example Usage

Using the Package Directly

from my_feature_package import TextFormatter, Validator

formatter = TextFormatter()
validator = Validator()

# Format text
result = formatter.to_title_case("hello world")
print(result)  # "Hello World"

# Validate email
is_valid = validator.is_email("user@example.com")
print(is_valid)  # True

Using the API

# Format text
curl -X POST "http://localhost:8000/format/title" \
  -H "Content-Type: application/json" \
  -d '{"text": "hello world"}'

# Validate email
curl -X POST "http://localhost:8000/validate/email" \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com"}'

Package Features

TextFormatter

  • to_title_case() - Convert to title case
  • to_snake_case() - Convert to snake_case
  • reverse_text() - Reverse text
  • capitalize_words() - Capitalize each word
  • remove_whitespace() - Remove all whitespace

Validator

  • is_email() - Validate email format
  • is_phone() - Validate phone number (10 digits)
  • is_strong_password() - Validate strong password requirements

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

my_feature_package-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

my_feature_package-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file my_feature_package-0.1.0.tar.gz.

File metadata

  • Download URL: my_feature_package-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for my_feature_package-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63c2c4bc74b777321ec2c9250cc7b2022bade51af2d786c35e31537e69ac1f5c
MD5 e694fc79fb1afbd27fd2ade174ac0b42
BLAKE2b-256 92ee5a5b99b39e0ecb3e5edcbbac3d27e5a0091a2b1a67860ab44125ed6d80bc

See more details on using hashes here.

File details

Details for the file my_feature_package-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for my_feature_package-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1700fb0bb787eb27f02b912fb68a01b22674fc2281c2482f21bcb8750ede693e
MD5 d51cd509d1dd70a7ef4bcc50c58261ab
BLAKE2b-256 4c79ea8908f5a75c84a4010d3005fe1121c3375dcdb57f0f08425674668ffc0c

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