Provides subclasses for common python types with additional functionality and convenience methods.
This library is currently still under development. The API will likely undergo significant changes that may break any code you write with it. The documentation will fall out of sync with the updates regularly until development slows down. Use it at your own risk.
Provides subclasses for certain python builtins (str, list, dict) and common complex types (datetime, Enum, DataFrame, BeautifulSoup) which add functionality and
convenience methods/properties. Most of these have better __repr__()
implementations than their superclass.
Str
class (subclasses str
)List
class (subclasses list
)list.append()
, list.clear()
etc.)Dict
class (subclasses dict
)dict.update()
, dict.clear()
etc.)Dict
instances when constructed and when settings an attribute or itemDateTime
class (subclasses datetime.datetime
)DateTime.delta()
method (timedelta addition and subtraction using keyword arguments)DateTime.strftime()
and DateTime.strptime()
.DateTime.Year
for DateTime.year
, DateTime.MicroSecond
for DateTime.microsecond
etc.) which
return that attribute as a string in various formats, based on the available format codes of the datetime class.Enum
class (subclasses aenum.Enum
)extend_enum
function directly as Enum.extend_enum()
Enum.names
and Enum.values
attributes that return listsValueEnum
subclass which returns the value of its members on attribute access, rather than the members themselves.AutoEnum
class which does not require values to be explicitly set, and sets the values to be lowercased versions of the nameMarkup
class (subclasses bs4.BeautifulSoup
)Frame
class (subclasses pandas.DataFrame
)Series
dtype when constructed with an iterable that only contains int
and None
(rather than using the default float64)Frame
as asciiFrame.to_excel()
formats the output file to an excel table, returns a path objectFrame.to_sql()
, with better SQL type selection, allows one of the columns (or the index) to be used as a primary key for the resulting SQL table.Frame.from_excel()
, capable of inferring table boundaries from messy spreadsheets using several rulesets, recasing the column names, and removing password protectionFrame
from an iterable of homogenous objectsProcess
class (subclasses subprocess.Popen)Process.wait()
method which prints any stdout to the console and returns a CompletedProcess
rather than just a return code.Color
class (subclasses colour.Color)Color.Name
Enum
which contains all the possible color names that can be passed to the Color()
constructor.Http
class (subclasses requests.Session)Http(base_url=)
argument which allows subsequent request to use shortened urls.NameSpace
class_
).Singleton
classSingleton
will return the same instance whenever constucted).To install use pip:
$ pip install pysubtypes
Or clone the repo:
$ git clone https://github.com/matthewgdv/subtypes.git
$ python setup.py install
Detailed usage examples coming soon.
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Report bugs at https://github.com/matthewgdv/subtypes/issues
If you are reporting a bug, please include:
Look through the GitHub issues for bugs. Anything tagged with "bug" and "help wanted" is open to whoever wants to implement a fix for it.
Look through the GitHub issues for features. Anything tagged with "enhancement" and "help wanted" is open to whoever wants to implement it.
The repository could always use more documentation, whether as part of the official docs, in docstrings, or even on the web in blog posts, articles, and such.
The best way to send feedback is to file an issue at https://github.com/matthewgdv/subtypes/issues.
If you are proposing a new feature:
Before you submit a pull request, check that it meets these guidelines:
If the pull request adds functionality, it should include tests and the docs should be updated. Write docstrings for any functions that are part of the external API, and add the feature to the README.md.
If the pull request fixes a bug, tests should be added proving that the bug has been fixed. However, no update to the docs is necessary for bugfixes.
The pull request should work for the newest version of Python (currently 3.7). Older versions may incidentally work, but are not officially supported.
Inline type hints should be used, with an emphasis on ensuring that introspection and autocompletion tools such as Jedi are able to understand the code wherever possible.
PEP8 guidelines should be followed where possible, but deviations from it where it makes sense and improves legibility are encouraged. The following PEP8 error codes can be safely ignored: E121, E123, E126, E226, E24, E704, W503
This repository intentionally disallows the PEP8 79-character limit. Therefore, any contributions adhering to this convention will be rejected. As a rule of thumb you should endeavor to stay under 200 characters except where going over preserves alignment, or where the line is mostly non-algorythmic code, such as extremely long strings or function calls.