Skip to main content

Library for working with file-likes as piped streams

Project description

Build Status codecov PyPI PyPI - Python Version License: MIT

fPipe

python framework for data manipulation and metadata extraction built around the python file-like api.

Disclaimer: framework is currently in Alpha, production use discouraged

Installing

for S3 support you need boto3

brew install python3
# apt, yum, apk...
pip3 install fpipe
# Optional
pip3 install boto3

Getting started

Simple example

Calculates size and md5 of stream, while storing stream to disk and prints content. When file is read finished, md5 is ready and printed

from fpipe.file import ByteFile
from fpipe.gen import LocalGen, MetaGen
from fpipe.meta import Path, SizeCalculated, MD5Calculated
from fpipe.workflow import WorkFlow

workflow = WorkFlow(
    LocalGen(pass_through=True),
    MetaGen(SizeCalculated, MD5Calculated)
)

for stream in workflow.compose(ByteFile(b'x' * 10, Path('x.dat')), ByteFile(b'y' * 20, Path('y.dat'))):
    print(f'\n{"-"*46}\n')
    print("Path name:", stream.meta(Path).value)
    print("Stream content: ", stream.file.read().decode('utf-8'))
    with open(stream.meta(Path).value) as f:
        print("File content:", f.read())
    print("Stream md5:", stream.meta(MD5Calculated).value)
    print("Stream size:", stream.meta(SizeCalculated).value)
Subprocess script example

Stores original stream, calculates md5, encrypts using cli, stores, calculates md5, decrypts using cli and stores. Using flush_iter() we know all files have been completely read(), so MD5Calculated will be readable.

from fpipe.file import ByteFile
from fpipe.gen import LocalGen, MetaGen, ProcessGen
from fpipe.meta import Path, MD5Calculated
from fpipe.workflow import WorkFlow

workflow = WorkFlow(
    MetaGen(MD5Calculated),
    LocalGen(pass_through=True),

    ProcessGen("gpg --batch --symmetric --passphrase 'secret'"),
    MetaGen(MD5Calculated),
    LocalGen(pass_through=True, pathname_resolver=lambda x: f'{x.meta(Path).value}.gpg'),

    ProcessGen("gpg --batch --decrypt --passphrase 'secret'"),
    MetaGen(MD5Calculated),
    LocalGen(pass_through=True, pathname_resolver=lambda x: f'{x.meta(Path).value}.decrypted')
)

for f in workflow.compose(ByteFile(b'x' * 10, Path('x.orig')), ByteFile(b'y' * 20, Path('y.orig'))).flush_iter():
    print(f'\n{"-"*46}\n')
    print("Original path:", f.meta(Path, 2).value)
    print("Original md5:", f.meta(MD5Calculated, 2).value, end='\n\n')

    print("Encrypted path:", f.meta(Path, 1).value)
    print("Encrypted md5:", f.meta(MD5Calculated, 1).value, end='\n\n')

    print("Decrypted path:", f.meta(Path).value)
    print("Decrypted md5:", f.meta(MD5Calculated).value)

See unittests for more examples

Run tests and verify pypi compatibility

To run tests install tox and twine with pip, go to project root and run tox

# python3 -m venv .venv
# Activate virtualenv
source .venv/bin/activate
# Run tests
tox -e py37
# Build distribution
python setup.py sdist bdist_wheel
# Validate distribution
twine check dist/*

Built With

Contributing

Bug-reports and pull requests on github

Versioning

Any version change could break the public API (until 1.0.0 release)

License

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

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

fpipe-0.0.13.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

fpipe-0.0.13-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file fpipe-0.0.13.tar.gz.

File metadata

  • Download URL: fpipe-0.0.13.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.1

File hashes

Hashes for fpipe-0.0.13.tar.gz
Algorithm Hash digest
SHA256 63dba26364d919c60e3fc4fe897598271086e868f03b5bcec838f1ffdd8098e9
MD5 4a27217579d488fc2b2a0f1cd3a372af
BLAKE2b-256 a359de1b4e0eb93ec977baa0f3f41bb4b982ce2b18ba1b2cb4270ffa3404513f

See more details on using hashes here.

File details

Details for the file fpipe-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: fpipe-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.1

File hashes

Hashes for fpipe-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 3bd7a8904eed619cd013a87b5a565109e0e488d2810258a721d7e86bf7fca51b
MD5 01eb0ef392643367974c3a9f4d5cebd6
BLAKE2b-256 b12fe69c3c25683dce2a6b644ed4dda56ca9ca28ca17aaebe26d5fa475e584ee

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