Skip to main content

No project description provided

Project description

fastpy-rs

License: MIT PyPI version

FastPy-RS is a high-performance Python library that provides optimized implementations of common functions using Rust. It's designed to be a collection of frequently used functions where performance matters, offering significant speed improvements over pure Python implementations.

Features

  • Blazing Fast: Leverages Rust's performance to provide significant speedups
  • Easy to Use: Simple Python interface
  • Growing Collection: New functions are added regularly

Currently Available Functions

  1. Token Frequency Counter
    • Counts word frequencies in a text (case-insensitive)
    • Example: {"hello": 2, "world": 1} for input "Hello hello world"

Installation

pip install fastpy-rs

Or from source:

pip install maturin
maturin develop

Usage

import fastpy_rs

# Count word frequencies in a text
text = "Hello hello world! This is a test. Test passed!"
frequencies = fastpy_rs.token_frequency(text)
print(frequencies)
# Output: {'hello': 2, 'world': 1, 'this': 1, 'is': 1, 'a': 1, 'test': 2, 'passed': 1}

Performance

Performance comparison between the Rust implementation and a Python implementation using spaCy, a popular industrial-strength NLP library:

Performance Test Results (average time per call):
Rust implementation: 0.000207 seconds
Python implementation: 0.014828 seconds
Speedup: 71.66x

The test compares the tokenization and frequency counting of a text sample. The Rust implementation shows a significant performance improvement over the Python/spaCy implementation, being approximately 4.7x faster in our tests. Note that spaCy provides additional NLP features beyond simple tokenization, while our Rust implementation is optimized specifically for the token frequency counting task.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

  1. Install Rust: https://www.rust-lang.org/tools/install
  2. Install maturin: pip install maturin
  3. Clone the repository
  4. Build in development mode: maturin develop
  5. Run tests: pytest tests/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Roadmap

📦 JSON / Data

  1. parse_json(string) -> dict
  2. serialize_json(obj, pretty=False) -> str
  3. parse_large_json_file(filepath) -> dict
  4. extract_json_field(json_str, path: str) -> Any (JSONPath-like)
  5. compare_json(json1, json2) -> bool
  6. validate_json(schema: dict, data: dict) -> bool
  7. minify_json(json_str: str) -> str
  8. pretty_print_json(json_str: str) -> str
  9. merge_json_objects(json1: dict, json2: dict) -> dict
  10. flatten_json(nested_dict: dict) -> dict

🌐 HTTP / Networking

  1. http_get(url, headers=None, timeout=10) -> str
  2. http_post(url, data, headers=None) -> str
  3. http_download(url, dest_path)
  4. http_request(method, url, headers, body) -> (code, body)
  5. fetch_json(url) -> dict
  6. http_head(url) -> headers
  7. http_retry_request(...)
  8. http_stream_lines(url) -> Iterator[str]
  9. http_check_redirect_chain(url) -> List[str]
  10. http_measure_latency(url) -> float

🔐 Hashing / Crypto

  1. sha256(data: bytes | str) -> str
  2. md5(data: bytes | str) -> str
  3. hmac_sha256(key, message) -> str
  4. blake3_hash(data) -> str
  5. is_valid_sha256(hexstr: str) -> bool
  6. secure_compare(a: str, b: str) -> bool

🧮 Data Processing / Encoding

  1. base64_encode(data: bytes) -> str
  2. base64_decode(data: str) -> bytes
  3. gzip_compress(data: bytes) -> bytes
  4. gzip_decompress(data: bytes) -> bytes
  5. url_encode(str) -> str
  6. url_decode(str) -> str
  7. csv_parse(csv_string) -> List[Dict]
  8. csv_serialize(data: List[Dict]) -> str
  9. bloom_filter_create(size: int, hash_funcs: int)
  10. bloom_filter_check(item: str) -> bool

⏱️ Performance / Utils

  1. benchmark_fn(callable, *args, **kwargs) -> float
  2. parallel_map(func, list, threads=4) -> list
  3. fast_deduplication(list) -> list
  4. sort_large_list(list) -> list
  5. fuzzy_string_match(a, b) -> score
  6. levenshtein_distance(a, b) -> int
  7. tokenize_text(text: str) -> List[str]
  8. fast_word_count(text: str) -> Dict[str, int]
  9. regex_search(pattern, text) -> List[str]
  10. regex_replace(pattern, repl, text) -> str

🧠 AI/ML Preprocessing

  1. normalize_vector(vec: List[float]) -> List[float]
  2. cosine_similarity(vec1, vec2) -> float
  3. token_frequency(text: str) -> Dict[str, int]
  4. encode_text_fast(text: str) -> List[int]

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

fastpy_rs-0.0.3-cp313-cp313-win_amd64.whl (688.8 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file fastpy_rs-0.0.3-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for fastpy_rs-0.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e10bc8904146585328caffe1a3b655d0290b4afe15681a2d6e39a3fdb18ce6be
MD5 6dd5e0f747e75f3c92e992772c4eee9e
BLAKE2b-256 05482a1e9742f26f8fcd2184f6de5156322209e609e60998f1b228ab8c6da8d6

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