Skip to main content

Transformers FastAPI Kit

A small, production-oriented wrapper around Hugging Face Transformers plus a FastAPI REST service for sentiment analysis.

Version 0.1.1 now includes a complete tutorial and a ZIP starter bundle inside the installed package.

Install

pip install "transformers-fastapi-kit[api]"

The first prediction downloads the default model (distilbert-base-uncased-finetuned-sst-2-english) from Hugging Face and caches it locally.

Python usage

from transformers_fastapi_kit import SentimentModel

model = SentimentModel()
print(model.predict("This package is excellent!"))
# {'label': 'POSITIVE', 'score': 0.99...}

Use a different model with SentimentModel(model_name="..."); pass device=0 for a CUDA GPU or leave the default -1 for CPU.

Run the API

From the project root:

pip install -e ".[api]"
uvicorn app.main:app --host 0.0.0.0 --port 8000

The interactive Swagger UI is then available at the API server's /docs route. For a public deployment, replace the local address with the public domain assigned to your API service.

curl -X POST http://127.0.0.1:8000/predict \\
  -H 'Content-Type: application/json' \\
  -d '{"text":"I love this API"}'

Endpoints: GET /health, POST /predict, and the generated OpenAPI schema at /openapi.json.

Included tutorial and ZIP bundle

The package includes transformers_fastapi_kit/resources/TUTORIAL.md and transformers_fastapi_kit/resources/transformers-fastapi-kit-starter.zip.

To locate them after installation:

from importlib.resources import files

resources = files("transformers_fastapi_kit") / "resources"
print(resources / "TUTORIAL.md")
print(resources / "transformers-fastapi-kit-starter.zip")

The full public documentation is available at https://transformers-ynoszgzv.manus.space.

Development

pip install -e ".[api,dev]"
pytest
python -m build
python -m twine check dist/*

License

MIT

Metadata

Release files for transformers-fastapi-kit 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for transformers-fastapi-kit 0.1.1
File Size Uploaded Provenance Actions
transformers_fastapi_kit-0.1.1.tar.gz 11.9 kB Without provenance Details for transformers_fastapi_kit-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for transformers-fastapi-kit 0.1.1
File Interpreter ABI Platform Actions
transformers_fastapi_kit-0.1.1-py3-none-any.whl Python 3 none any Details for transformers_fastapi_kit-0.1.1-py3-none-any.whl

Total release size: 22.8 kB

Release files / transformers_fastapi_kit-0.1.1.tar.gz

Download URL transformers_fastapi_kit-0.1.1.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
53352aab92659f9c840d3d593128abf913a4eb432ca3d806843b56c413f01655
BLAKE2b-256 checksum
How to use checksums
7f1e2cd5c6cc74ea696f51a8618e603497f98013221eb6f7b69ee4446887073e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / transformers_fastapi_kit-0.1.1-py3-none-any.whl

Download URL transformers_fastapi_kit-0.1.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ecb446442ecddb1e7368a3f76f78871a02d744257a468e5ecf3a06abc7174a84
BLAKE2b-256 checksum
How to use checksums
7c5e995cd416a0970e7f87adf851e7304e40c7ccfae9e75778be36270127ab55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for transformers-fastapi-kit 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page