Saravanan666/pypi-org huggingface dataset:
Package: withhacks
withhacks:  building blocks for with-statement-related hackeryThis module is a collection of useful building-blocks for hacking the Python
“with” statement.  It combines ideas from several neat with-statement hacks
I found around the internet into a suite of re-usable components:http://www.mechanicalcat.net/richard/log/Python/Something_I_m_working_on.3http://billmill.org/multi_line_lambdas.htmlhttp://code.google.com/p/ouspg/wiki/AnonymousBlocksInPythonBy subclassing the appropriate context managers from this module, you can
easily do things such as:skip execution of the code inside the with-statementset local variables in the frame executing the with-statementcapture the bytecode from inside the with-statementcapture local variables defined inside the with-statementBuilding on these basic tools, this module also provides some useful prebuilt
hacks:xargs:call a function with additional arguments defined in the
body of the with-statementxkwargs:call a function with additional keyword arguments defined
in the body of the with-statementnamespace:direct all variable accesses and assignments to the attributes
of a given object (like “with” in JavaScript or VB)keyspace:direct all variable accesses and assignments to the keys of
of a given object (like namespace() but for dicts)WithHacks makes extensive use of Noam Raphael’s fantastic “byteplay” module;
since the official byteplay distribution doesn’t support Python 2.6, a local
version with appropriate patches is included in this module.
Package: withings-api
Python withings-apiPython library for the Withings Health APIWithings Health APIhttps://developer.withings.com/oauth2/Uses OAuth 2.0 to authenticate. You need to obtain a client id
and consumer secret from Withings by creating an application
here:http://developer.withings.com/oauth2/Installationpip install withings-apiUsageFor a complete example, checkout the integration test inscripts/integration_test.py. It has a working example on how to use the API.fromwithings_apiimportWithingsAuth,WithingsApi,AuthScopefromwithings_api.commonimportget_measure_value,MeasureTypeauth=WithingsAuth(client_id='your client id',consumer_secret='your consumer secret',callback_uri='your callback uri',mode='demo',# Used for testing. Remove this when getting real user data.scope=(AuthScope.USER_ACTIVITY,AuthScope.USER_METRICS,AuthScope.USER_INFO,AuthScope.USER_SLEEP_EVENTS,))authorize_url=auth.get_authorize_url()# Have the user goto authorize_url and authorize the app. They will be redirected back to your redirect_uri.credentials=auth.get_credentials('code from the url args of redirect_uri')# Now you are ready to make calls for data.api=WithingsApi(credentials)meas_result=api.measure_get_meas()weight_or_none=get_measure_value(meas_result,with_measure_type=MeasureType.WEIGHT)BuildingBuilding, testing and lintings of the project is all done with one script. You only need a few dependencies.Dependencies:python3 in your path.The python3venvmodule.The build script will setup the venv, dependencies, test and lint and bundle the project../scripts/build.shIntegration TestingThere exists a simple integration test that runs against Withings' demo data. It's best to run this after you have
successful builds.Note: after changing the source, you need to run build for the integration test to pickup the changes../scripts/build.shsource./venv/bin/activate
./scripts/integration_test.py--client-id<yourclientid>--consumer-secret<yourconsumersecret>--callback-uri<yourclalbackuri>The integration test will cache the credentials in a<project root>/.credentialsfile between runs. If you get an error saying
the access token expired, then remove that credentials file and try again.
Package: withings-api-cdt
Python withings-apiPython library for the Withings Health APIWithings Health APIhttps://developer.withings.com/oauth2/Uses OAuth 2.0 to authenticate. You need to obtain a client id
and consumer secret from Withings by creating an application
here:http://developer.withings.com/oauth2/Installationpython -m pip install withings_api_cdtUsageFor a complete example, checkout the integration test inscripts/integration_test.py. It has a working example on how to use the API.fromwithings_apiimportWithingsAuth,AuthScopefromwithings_api.apiimportWithingsApifromwithings_api.commonimportget_measure_value,MeasureTypeauth=WithingsAuth(client_id='your client id',consumer_secret='your consumer secret',callback_uri='your callback uri',mode='demo',# Used for testing. Remove this when getting real user data.scope=(AuthScope.USER_ACTIVITY,AuthScope.USER_METRICS,AuthScope.USER_INFO,AuthScope.USER_SLEEP_EVENTS,))authorize_url=auth.get_authorize_url()# Have the user goto authorize_url and authorize the app. They will be redirected back to your redirect_uri.credentials=auth.get_credentials('code from the url args of redirect_uri')# Now you are ready to make calls for data.api=WithingsApi(credentials)meas_result=api.measure_get_meas()weight_or_none=get_measure_value(meas_result,with_measure_type=MeasureType.WEIGHT)BuildingBuilding, testing and lintings of the project is all done with one script. You only need a few dependencies.Dependencies:python3 in your path.The python3venvmodule.The build script will setup the venv, dependencies, test and lint and bundle the project../scripts/build.shIntegration TestingThere exists a simple integration test that runs against Withings' demo data. It's best to run this after you have
successful builds.Note: after changing the source, you need to run build for the integration test to pickup the changes../scripts/build.shsource./venv/bin/activate
./scripts/integration_test.py--client-id<yourclientid>--consumer-secret<yourconsumersecret>--callback-uri<yourclalbackuri>The integration test will cache the credentials in a<project root>/.credentialsfile between runs. If you get an error saying
the access token expired, then remove that credentials file and try again.
Package: withlog
Logging as a context manager.Visually inspired by howCredolooks like, I always find difficult to communicate with user in command
line interface. So this is a logging/printing system which is more block
based than line base, and with color also.The following will show a nice formatted message :withMessage('Hello there')aslog:log('This is a Logging message context manager')log('it support nesting and will render in a User friendly way')log('I need to fix multi\nline\nstring')You can nest these:withMessage('Hello there')aslog:log('This is a Logging message context manager')log('it support nesting and will render in a User friendly way')log('I need to fix multi\nline\nstring')withWarning('Nested it does support')aslog1:log1('like Yoda speach order ')log1('of words are')withCritical('Come to the dark side')aslog2:log2('we have cookies')withOK("Paternity test")aslog3:log3('I am your father')To get nested messages:
Package: with-op
with-op scriptScript to stash 1Password CLI 2.x credentials into local keychainFree software: MIT licenseDocumentation:https://with-op.readthedocs.io.SetupInstall1Password command-line tool-brew install –cask 1password-cli, for instance.Installjqdependency -brew install jq, for instance.Installwith-op-pip3 install with_opInvoke:with-op op get item “My login to some site”FeaturesInstalls session keys into your OS keychain instead of in a single shell’s environment.Once one user window authenticates withop, all that are authorized to see the keychain are authorized to useop.with-opwill re-prompt for your password when your session expires.CreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.1.0 (2020-12-18)First release on PyPI.
Package: with-partial
WithPartialIntroductionWithPartial is a simple utility for functional piping in Python.
The package exposes a context manager (used withwith) calledPipeContext, that allows you to access any function in any scope as a partial, meaning that it's naturally pipeable.
Here's a contrived example from the test suite:importnumpyasnpfromwith_partialimportPartialContextfrompipetoolsimportpipewithPartialContext()as_:ret=(10>pipe|_.np.ones()|_.np.reshape(newshape=(5,2))|_.np.mean()|_.int())assertret==1As you can see, we were able to call bothnumpyand built-in functions on the_object, and it executed the pipeline similarly to say R'smagrittrpackage.Installationpipinstallwith_partialUsageActually WithPartial doesn't provide an actual piping mechanism, but it does add a useful syntax for use with pipes.
For the actual piping mechanism, I suggest that you trypipetools, which this package is actually tested against.WithPartial provides a single class:PipeContext.
The way you usePipeContextis by first using it as a context manager:withPipeContext()as_:Then, using the return value of the context manager, which we have named_(but you could call it anything), you access attributes and items (using.attror["key"]or[0]) to locate the function you want and then you finally call it(), which will create the partial.
You can use positional and keyword arguments at this point if you needFor more usage information, refer to thetest suite.TestsNote: you will needpoetryinstalled.gitclonehttps://github.com/multimeric/WithPartial.gitcdWithPartial
poetryinstall--extraspipetools
poetryrunpytesttest/
Package: withstopwatch
# >>> from withstopwatch import StopwatchBasicusage:>>>withStopwatch():...print('<some activity to be measured>')<someactivitytobemeasured>0msFields:>>>withStopwatch()ass:...pass0ms>>>assertisinstance(s.label,str)ands.label=='0 ms'>>>assertisinstance(s.ms,int)ands.ms==0>>>assertisinstance(s.s,int)ands.s==0>>>assertisinstance(s.seconds,float)ands.seconds>0>>>assertisinstance(s.timedelta,datetime.timedelta)>>>assertisinstance(s.start,datetime.datetime)>>>assertisinstance(s.stop,datetime.datetime)>>>asserts.stop-s.start==s.timedelta`str`and`repr`:>>>assertstr(s)==s.label>>>repr(s)# doctest: +ELLIPSIS'<Stopwatch: datetime.timedelta(...)>'Silencing:>>>withStopwatch(template=None)ass:...pass>>>asserts.labelisNone>>>withStopwatch(print=None)ass:...pass>>>asserts.label=='0 ms'Specialprint:>>>withStopwatch(print=lambdaline:print('DEBUG:',line))ass:...passDEBUG:0msTemplates:>>>withStopwatch(template='passing'):...pass0ms:passing>>>withStopwatch('passing'):...pass0ms:passing>>>withStopwatch('{ms}ms'):...pass0ms>>>withStopwatch('{s}s'):...pass0s>>>withStopwatch('{:.03f}(i.e.{seconds:.03f})'):...pass0.000(i.e.0.000)>>>withStopwatch('{timedelta}'):...pass# doctest: +ELLIPSIS0:00:00...>>>withStopwatch('from{start!r}to{stop!r}')ass:...pass# doctest: +ELLIPSISfromdatetime.datetime(...)todatetime.datetime(...)Withanexception(note:duetolimitationsof`doctest`,wecan't checkeasilyboththatsomethingisprintedandthatanexceptionisraised):>>>withStopwatch(print=None):...raiseException()Traceback(mostrecentcalllast):Exception>>>try:...withStopwatch()ass:...raiseException()...exceptExceptionasexc:...print(repr(s))# doctest: +ELLIPSIS0ms(failed)<Stopwatch:datetime.timedelta(...)>>>>try:...withStopwatch('abc')ass:...raiseException()...exceptExceptionasexc:...print(repr(s))# doctest: +ELLIPSIS0ms:abc(failed)<Stopwatch:datetime.timedelta(...)>Testingwith`time.sleep`(note:thetestsmayfailduringaslowerrun):>>>importtime>>>withStopwatch()ass:...time.sleep(0.1)100ms>>>assert0.1<s.seconds<0.2Embeddedstopwatches:>>>withStopwatch('outer'):...withStopwatch('inner'):...pass0ms:inner0ms:outerMeasuringtheoverheadofStopwatchusingStopwatchitself(note:thetestsmayfailduringaslowerrun):>>>withStopwatch(print=None)ass1:...withStopwatch('inner')ass2:...pass0ms:inner>>>withStopwatch(print=None)ass3:...pass>>>overhead=s1.seconds-s3.seconds>>>assert0<=overhead<0.0001...# ~20 us on i5@2.60GHz, Python 3.6.0, Linux
Package: with-time
Context Managers and Decorator for common time operationsQuick startInstallationpipintallwith-timeUsageMeasuring duration, with PrintingTimer or LoggingTimerwith_timer.PrintingTimer(label: str = None, timer: Callable[[], float] = time.time)Prints out how long context operation or function took. Message is prepended withlabel. By default elapsed running time will be measured but othertimemethods can be
utilized such astime.process_time,time.monotomic, and so on.>>>importtime>>>fromwith_timeimportPrintingTimer>>>>>># Context Manager Example>>>withPrintingTimer("Example"):...time.sleep(.1337)...Example:0.13398265838623047seconds>>>>>># Decorator Example>>>@PrintingTimer("Decorator Example")...deffoo():...time.sleep(.1337)...>>>foo()DecoratorExample:0.13398265838623047secondswith_timer.LoggingTimer(label: str = None, log_level: int = None, timer: Callable[[], float] = time.time)LoggingTimer works just the same way as PrintinTimer except duration is logged
rather than printed. Log level can be customized usinglogging.debug, logging.warning…>>>importtime>>>importlogging>>>fromwith_timeimportLoggingTimer>>>logging.basicConfig(force=True)>>>>>># Context Manager Example>>>withLoggingTimer("Example"):...time.sleep(.1337)...INFO:with_time.timer:Example:0.13399600982666016seconds>>>>>># Decorator Example>>>@LoggingTimer("Decorator Example")...deffoo():...time.sleep(.1337)...>>>foo()INFO:with_time.timer:DecoratorExample:0.13396501541137695secondswith_time.SignalTimeout(seconds: float, exception=None)Raise an exception as an execution timeout. SignalTimeout usessignalimplementation
which is only supported on Unix like os. By defaultwith_time.exceptions.TimeoutErrorbut this can be changed by passing any initialized exception object asexceptionSignalTimeout does attempt to restore signals it overwrites which make some but not all
nested scenarios of timeout work.>>>importtime>>>fromwith_timeimportSignalTimeout>>>withSignalTimeout(.1000):...time.sleep(.1337)...Traceback(mostrecentcalllast):File"<stdin>",line2,in<module>File".../with_time/timeout.py",line21,in_handlerraiseself.exceptionwith_time.exceptions.TimeoutError:Timedout>>>>>># Custom Exception>>>withSignalTimeout(.1000,exception=RuntimeError("Oops")):...time.sleep(.1337)...Traceback(mostrecentcalllast):File"<stdin>",line2,in<module>File".../with_time/timeout.py",line21,in_handlerraiseself.exceptionRuntimeError:Oops
Package: withtimer
WITHTIMERDescriptionWithTimer is a Python module for benchmarking your code. It has the following features:Simple useJust create a timer object, and it times execution until it goes out of scopeArbitrarily nested timersCreate as many nested timers as you wantEach timer pushes itself to a stack, and pops itself off when destroyedExample usagewithTimer(name="Something slow"):do_something_slow()Timing is turned off by default, and can be optionally turned on. You can instrument your code with timers, and leave them in when you're not using them:ifargs.enable_timing:Timer.enable_timing(args.enable_timing)withTimer(name="Timers are a sometimes treat"):do_something()You can nest timers:withTimer(name="Outer timer"):foriinrange(0,100000):withTimer(name="Hope this isn't O(n^2)"):do_something_critical()Here's a complete example:fromtimeimportsleepfromwithtimer.withtimerimportTimerdeffunc1(count):foriinrange(0,3):withTimer(name="Calling func2"):func2(2)print("func1 sleeping{}".format(count))sleep(count)deffunc2(count):print("func2 sleeping{}".format(count))sleep(count)if__name__=="__main__":Timer.enable_timing(True)withTimer(name="main"):foriinrange(0,3):ifi%2>0:func1(i+1)Output:$python3./example.py[main] start[Calling func2] startfunc2 sleeping 2[Calling func2] end	Elapsed time: 2.003 seconds[Calling func2] startfunc2 sleeping 2[Calling func2] end	Elapsed time: 2.003 seconds[Calling func2] startfunc2 sleeping 2[Calling func2] end	Elapsed time: 2.003 secondsfunc1 sleeping 2[main] end	Elapsed time: 8.015 seconds$
Package: withtray
Run any blocking command with systray iconThis is mainly useful for background processes.
It gives you an indication that it's running and allows
you to send aSIGINTsignal by clicking on theQuitmenu item.# Install withtray
pip install --user withtray

# Copy your icon to ~/.local/share/icons and run
withtray 'polly server' --name polly --icon polly
Package: with-utils
With UtilsUtils that we've used a lot at WITH.iterIteration-related utilsn_gramsProvides a way to create n_grams from an iteratorfromwith_utils.iterimportn_gramsassertlist(n_grams([1,2,3,4],2))==[(1,2),(2,3),(3,4)]return_listTransforms an iterator into a function that returns a list.fromwith_utils.iterimportreturn_list@return_listdeffoo():yield1yield2yield3assertfoo()==[1,2,3]
Package: with-venv
venv Context ManagerContext manager controls venv allowing functions to be run in a different interpreter.Free software: ISC licenseDocumentation:https://with-venv.readthedocs.org.FeaturesTODOCreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.0.1 (2016-04-21)First release on PyPI.
Package: withwait
WithwaitA simple utility to ensure that sleep operations always complete, even if an
exception happens within the with statement.Usagefromwithwaitimportwait# Start a 2 second wait timerwithwait(2):# These operations happen while the timer is runprint("Started timer")# Even if an error is raised, the timer will always be allowed to complete# before the withwait block is closedraiseException("Yikes")# The exception isn't actually caught so this code won't runprint("This never prints")Cancelling a timerIf you need to stop the timer during the operation, you can stop it using thecancelmethod. Normal running will resume from the end of thewithstatement.fromwithwaitimportwaitwithwait(1)astimer:# Stop the timertimer.cancel()# Code after this point in the with statement won't be run# Program flow resumes normally afterprint("Ok")Different timers can be cancelled separately - if you cancel one timer, all
other timers will run to completion.Aborting a timerIf you don't want to resume normal program flow after thewithstatement,
you can stop the timer using theabortmethod.fromwithwaitimportwait,WithwaitAborttry:withwait(1)astimer:# Abort the timertimer.abort()# Code after this point in the with statement won't be run# And code after the with statement won't be run eitherprint("Nope")# We need to catch the exception ourselvesexceptWithwaitAbort:print("Caught")Arguments can be provided to theabortmethod which will be
given as arguments to the exceptionDifferent timers can be aborted separately - if you cancel one timer, all
other timers will run to completion.Aborting all timersIf you want to cancel anything, you can call theabort_allmethod. You can
also raise aWithwaitAbortAllexception, which will have the same effect.fromwithwaitimportwait,WithwaitAbortAlltry:withwait(1):withwait(1):withwait(1)astimer:# Abort all timerstimer.abort_all()exceptWithwaitAbortAll:print("All timers stopped")
Package: witness-etl
witnessA minimal batch processing ETL library.Intended to be simple and concise.Made to wrap common instrumental approaches in a high-level abstraction.
And for fun.Installationpython3 -m pip install witness-etlConceptsBatchThe main concept of the lib. It's a container for some useful data and metadata.fromwitnessimportBatchbatch=Batch()print(batch)VersioningThis lib supportsSemVerapproach for all packages released.ContributingWant to help or got questions?Contact me.
Package: witnet-lib
Witnet LibraryThis library is light client implementation for witnet node, capable of directly interacting with witnet node. ( SeeWitnet.iofor more information )FeaturesAllows sending proto messages to witnet node.Performs handshake with witnet node.Iterates over the nodes in witnet network in a DAG(directed acyclic graph) fashionHow to usePerforming handshake with witnet node.fromwitnet_lib.witnet_clientimportWitnetClientfromwitnet_lib.utilsimportAttrDict# Setting configconfig=AttrDict({"genesis_sec":1602666000,"magic":40941,"sender_addr":"127.0.0.1:21341","time_per_epoch":45,})client=WitnetClient(config)client.handshake("127.0.0.1:21337")client.close()Listening to messages from witnet node.#After performing handshake with node.msg=client.receive_msg()# this returns serialized message from nodeparsed_msg=client.msg_handler.parse_msg(msg)# we need to parse the messageprint(parsed_msg)print(parsed_msg.kind)The connection is ofkeep alivetype, so messages are continually sent from witnet node. To listen for all messages:whileTrue:msg=client.receive_msg()# this returns serialized message from nodeparsed_msg=client.msg_handler.parse_msg(msg)print(parsed_msg)Sending message to witnet node.#After performing handshake with node.cmd=client.msg_handler.version_cmd("127.0.0.1:21337")# this returns a version messageprint(cmd)msg=client.msg_handler.serialize(cmd)# this returns serialized messsage ready to be sent to nodeclient.send_msg(msg)msg_from_node=client.receive_msg()# this returns only one whole message from nodemsg_from_node_with_msg_len,reced_or_not=client.tcp_handler.receive(30)# this returns x bytes from connection streamMapping all nodes in the network (DAG fashion)fromwitnet_libimportutilsfromwitnet_lib.map_nodesimportMapNodesconfig=utils.AttrDict({"genesis_sec":1602666000,"magic":40941,"sender_addr":"127.0.0.1:21341","time_per_epoch":45,})mapper=MapNodes(config,["127.0.0.1:21337"])# provide initialisation peersall_nodes,active_map=mapper.start_mapping_workers(3)# number of connections allowed to be created in parallelprint(all_nodes)print(active_map)# it contains node id with the list of its peers
Package: witokit
WiToKitWelcome toWiToKit, a Python toolkit to download and generate preprocessed Wikipedia dumps for all languages.WiToKit can be used to converts a Wikipedia archive into a single .txt file, one (tokenized) sentence per line.Note: WiToKit currently only supportsxx-pages-articles.xml.xx.bz2Wikipedia archives corresponding to articles, templates, media/file descriptions, and primary meta-pages.Installpip3installwitokitOn python3.5 you may need to pass on the--process-dependency-linkflag:pip3installwitokit--process-dependency-linkUseDownloadTo download a .bz2-compressed Wikipedia XML dump, do:witokitdownload⁠\--langlang_wp_code\--datewiki_date\--output/abs/path/to/output/dir/where/to/store/bz2/archives\--num-threadsnum_cpu_threadsFor example, to download the latest English Wikipedia, do:witokitdownload⁠--langen--datelatest--output/abs/path/to/output/dir--num-threads2The--langparameter expects the WP (language) code corresponding
to the desired Wikipedia archive.
Check out the full list of Wikipedias with their corresponding WP codeshere.The--dateparameter expects a string corresponding to one of the dates
found under the Wikimedia dump site corresponding to a given Wikipedia dump
(e.g.https://dumps.wikimedia.org/enwiki/for the English Wikipedia).ImportantKeep num-threads <= 3 to avoid rejection from Wikimedia serversExtractTo extract the content of the downloaded .bz2 archives, do:witokitextract\--input/abs/path/to/downloaded/wikipedia/bz2/archives\--num-threadsnum_cpu_threadsProcessTo preprocess the content of the extracted XML archives and output a single .txt file, tokenize, one sentence per line:witokitprocess\--input/abs/path/to/wikipedia/extracted/xml/archives\--output/abs/path/to/single/output/txt/file\--lower\# if set, will lowercase text--num-threadsnum_cpu_threadsPreprocessing for all languages is performed withPolyglot.SampleYou can also use WiToKit to sample the content of a preprocess .txt file, using:witokitsample\--input/abs/path/to/witokit/preprocessed/txt/file\--percent\# percentage of total lines to keep--balance# if set, will balance sampling, otherwise, will take top n sentences only