diff --git a/trafaret/__init__.py b/trafaret/__init__.py
index 19f68e9..13a10af 100644
--- a/trafaret/__init__.py
+++ b/trafaret/__init__.py
@@ -23,6 +23,7 @@ from .base import (
     String,
     AnyString,
     Bytes,
+    ToBytes,
     FromBytes,
     Callable,
     Bool,
@@ -84,6 +85,7 @@ __all__ = (
     "ToDateTime",
     "AnyString",
     "Bytes",
+    "ToBytes",
     "FromBytes",
     "Float",
     "ToFloat",
diff --git a/trafaret/base.py b/trafaret/base.py
index b6f7e53..65496e5 100644
--- a/trafaret/base.py
+++ b/trafaret/base.py
@@ -684,6 +684,34 @@ class Bytes(String):
     TYPE_ERROR_CODE = codes.IS_NOT_A_BYTES_STRING
 
 
+class ToBytes(Trafaret):
+    """Get str and try to encode it with given encoding, utf-8 by default."""
+    def __init__(self, encoding='utf-8'):
+        self.encoding = encoding
+
+    def check_and_return(self, value):
+        if isinstance(value, BYTES_TYPE):
+            return value
+        elif isinstance(value, STR_TYPE):
+            try:
+                return value.encode(self.encoding)
+            except UnicodeError:
+                raise self._failure(
+                    'value cannot be encoded with %s encoding' % self.encoding,
+                    value=value,
+                    code=codes.CANNOT_BE_ENCODED,
+                )
+        else:
+            self._failure(
+                'value is not str/bytes type',
+                value=value,
+                code=codes.IS_NOT_A_STRING,
+            )
+
+    def __repr__(self):
+        return '<ToBytes>'
+
+
 class AnyString(String):
     str_type = (BYTES_TYPE, STR_TYPE)
 
diff --git a/trafaret/codes.py b/trafaret/codes.py
index afb0f68..cc71a96 100644
--- a/trafaret/codes.py
+++ b/trafaret/codes.py
@@ -29,6 +29,7 @@ IS_NOT_CALLABLE = 'is_not_callable'
 
 IS_NOT_BYTES = 'is_not_bytes'
 CANNOT_BE_DECODED = 'cannot_be_decoded'
+CANNOT_BE_ENCODED = 'cannot_be_encoded'
 
 IS_NOT_A_LIST = 'is_not_a_list'
 TOO_SHORT = 'too_short'

No FromString/ToBytes?
There is a FromBytes object to convert to string. It would be nice to have the inverse to convert to bytes.
diff --git a/tests/test_base.py b/tests/test_base.py
index bff4193..8ca7cae 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -706,6 +706,24 @@ class TestDateTimeTrafaret:
         assert repr(to_datetime_repr) == '<ToDateTime %Y-%m-%d %H:%M>'
 
 
+class TestToBytesTrafaret:
+    def test_bytes(self):
+        res = t.ToBytes().check("foo")
+        assert res == b'foo'
+        res = t.ToBytes()("")
+        assert res == b''
+        res = t.ToBytes().check(b"foo")
+        assert res == b'foo'
+        res = extract_error(t.ToBytes(), 1)
+        assert res == 'value is not str/bytes type'
+        res = extract_error(t.ToBytes('ascii'), '£')
+        assert res == 'value cannot be encoded with ascii encoding'
+
+    def test_repr(self):
+        res = t.ToBytes()
+        assert repr(res) == '<ToBytes>'
+
+
 class TestFromBytesTrafaret:
     def test_bytes(self):
         res = t.FromBytes().check(b"foo")

pip install -e .[dev]
parse_log_pytest
pytest
pytest flake8 pylint pymongo python-dateutil pytest-cov pytest-asyncio
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
astroid==3.3.9
coverage==7.8.0
dill==0.3.9
dnspython==2.7.0
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
flake8==7.2.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
isort==6.0.1
mccabe==0.7.0
packaging @ file:///croot/packaging_1734472117206/work
platformdirs==4.3.7
pluggy @ file:///croot/pluggy_1733169602837/work
pycodestyle==2.13.0
pyflakes==3.3.2
pylint==3.3.6
pymongo==4.11.3
pytest @ file:///croot/pytest_1738938843180/work
pytest-asyncio==0.26.0
pytest-cov==6.0.0
python-dateutil==2.9.0.post0
six==1.17.0
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
tomlkit==0.13.2
-e git+https://github.com/Deepwalker/trafaret.git@6bd672cb84e5e7901afbda78a03e83d704bab7e7#egg=trafaret
typing_extensions==4.13.0

name: trafaret
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - astroid==3.3.9
      - coverage==7.8.0
      - dill==0.3.9
      - dnspython==2.7.0
      - flake8==7.2.0
      - isort==6.0.1
      - mccabe==0.7.0
      - platformdirs==4.3.7
      - pycodestyle==2.13.0
      - pyflakes==3.3.2
      - pylint==3.3.6
      - pymongo==4.11.3
      - pytest-asyncio==0.26.0
      - pytest-cov==6.0.0
      - python-dateutil==2.9.0.post0
      - six==1.17.0
      - tomlkit==0.13.2
      - typing-extensions==4.13.0
prefix: /opt/conda/envs/trafaret

tests/test_base.py::TestToBytesTrafaret::test_bytes tests/test_base.py::TestToBytesTrafaret::test_repr
tests/test_base.py::TestTrafaret::test_any tests/test_base.py::TestTrafaret::test_ensure tests/test_base.py::TestTrafaret::test_is_valid tests/test_base.py::TestAnyTrafaret::test_any tests/test_base.py::TestAnyTrafaret::test_repr tests/test_base.py::TestAtomTrafaret::test_atom tests/test_base.py::TestBoolTrafaret::test_bool[True-True] tests/test_base.py::TestBoolTrafaret::test_bool[False-False] tests/test_base.py::TestBoolTrafaret::test_extract_error tests/test_base.py::TestBoolTrafaret::test_repr tests/test_base.py::TestCallTrafaret::test_call tests/test_base.py::TestCallTrafaret::test_repr tests/test_base.py::TestCallTrafaret::test_should_be_callable tests/test_base.py::TestCallableTrafaret::test_callable tests/test_base.py::TestCallableTrafaret::test_repr tests/test_base.py::TestBasics::test_callable tests/test_base.py::TestBasics::test_auto_call tests/test_base.py::TestBasics::test_class tests/test_base.py::TestBasics::test_upper tests/test_base.py::TestDictTrafaret::test_base tests/test_base.py::TestDictTrafaret::test_repr tests/test_base.py::TestDictTrafaret::test_key_shadowed tests/test_base.py::TestDictTrafaret::test_kwargs_extra tests/test_base.py::TestDictTrafaret::test_kwargs_ignore tests/test_base.py::TestDictTrafaret::test_add_kwargs_ignore tests/test_base.py::TestDictTrafaret::test_add_kwargs_ignore_any tests/test_base.py::TestDictTrafaret::test_add_kwargs_extra tests/test_base.py::TestDictTrafaret::test_callable_key tests/test_base.py::TestDictTrafaret::test_base2 tests/test_base.py::TestDictTrafaret::test_base3 tests/test_base.py::TestDictTrafaret::test_add tests/test_base.py::TestDictTrafaret::test_bad_add_names tests/test_base.py::TestDictTrafaret::test_bad_add_to_names tests/test_base.py::TestDictTrafaret::test_add_to_names_list_of_keys tests/test_base.py::TestDictTrafaret::test_add_to_names_dict_of_keys tests/test_base.py::TestDictTrafaret::test_bad_args_add tests/test_base.py::TestDictTrafaret::test_mapping_interface tests/test_base.py::TestDictTrafaret::test_keys_must_be_callable tests/test_base.py::TestDictTrafaret::test_clone tests/test_base.py::TestDictKeys::test_dict_keys tests/test_base.py::TestEnumTrafaret::test_enum tests/test_base.py::TestEnumTrafaret::test_repr tests/test_base.py::TestToFloat::test_float tests/test_base.py::TestToFloat::test_float_repr tests/test_base.py::TestToFloat::test_float_meta_repr tests/test_base.py::TestForwardTrafaret::test_forward tests/test_base.py::TestForwardTrafaret::test_repr tests/test_base.py::TestToIntTrafaret::test_int tests/test_base.py::TestToIntTrafaret::test_repr tests/test_base.py::TestList::test_list tests/test_base.py::TestList::test_list_meta tests/test_base.py::TestList::test_2_0_regression tests/test_base.py::TestList::test_list_repr tests/test_base.py::TestIterableTrafaret::test_iterable tests/test_base.py::TestIterableTrafaret::test_repr tests/test_base.py::TestMappingTrafaret::test_mapping tests/test_base.py::TestMappingTrafaret::test_repr tests/test_base.py::TestNullTrafaret::test_null tests/test_base.py::TestNullTrafaret::test_repr tests/test_base.py::TestOrNotToTest::test_or tests/test_base.py::TestOrNotToTest::test_operator tests/test_base.py::TestOrNotToTest::test_repr tests/test_base.py::TestAndTest::test_and tests/test_base.py::TestAndTest::test_raise_error tests/test_base.py::TestAndTest::test_repr tests/test_base.py::TestToBoolTrafaret::test_str_bool[t-True] tests/test_base.py::TestToBoolTrafaret::test_str_bool[true-True] tests/test_base.py::TestToBoolTrafaret::test_str_bool[y-True] tests/test_base.py::TestToBoolTrafaret::test_str_bool[yes-True] tests/test_base.py::TestToBoolTrafaret::test_str_bool[On-True] tests/test_base.py::TestToBoolTrafaret::test_str_bool[1-True0] tests/test_base.py::TestToBoolTrafaret::test_str_bool[1-True1] tests/test_base.py::TestToBoolTrafaret::test_str_bool[1.0-True] tests/test_base.py::TestToBoolTrafaret::test_str_bool[True-True] tests/test_base.py::TestToBoolTrafaret::test_str_bool[false-False] tests/test_base.py::TestToBoolTrafaret::test_str_bool[n-False] tests/test_base.py::TestToBoolTrafaret::test_str_bool[no-False] tests/test_base.py::TestToBoolTrafaret::test_str_bool[off-False] tests/test_base.py::TestToBoolTrafaret::test_str_bool[0-False0] tests/test_base.py::TestToBoolTrafaret::test_str_bool[0-False1] tests/test_base.py::TestToBoolTrafaret::test_str_bool[0.0-False] tests/test_base.py::TestToBoolTrafaret::test_str_bool[False-False] tests/test_base.py::TestToBoolTrafaret::test_extract_error tests/test_base.py::TestToBoolTrafaret::test_repr tests/test_base.py::TestStringTrafaret::test_string tests/test_base.py::TestStringTrafaret::test_repr tests/test_base.py::TestDateTrafaret::test_date tests/test_base.py::TestDateTrafaret::test_to_date tests/test_base.py::TestDateTrafaret::test_repr tests/test_base.py::TestDateTimeTrafaret::test_datetime tests/test_base.py::TestDateTimeTrafaret::test_to_datetime tests/test_base.py::TestDateTimeTrafaret::test_repr tests/test_base.py::TestFromBytesTrafaret::test_bytes tests/test_base.py::TestFromBytesTrafaret::test_repr tests/test_base.py::TestRegexpTrafaret::test_regexp tests/test_base.py::TestRegexpTrafaret::test_regexp_raw tests/test_base.py::TestRegexpTrafaret::test_regexp_raw_error tests/test_base.py::TestRegexpTrafaret::test_repr tests/test_base.py::TestTrafaretMeta::test_meta tests/test_base.py::TestTrafaretMeta::test_repr tests/test_base.py::TestTupleTrafaret::test_tuple tests/test_base.py::TestTupleTrafaret::test_repr tests/test_base.py::TestTypeTrafaret::test_type tests/test_base.py::TestTypeTrafaret::test_repr tests/test_base.py::TestSubclassTrafaret::test_subclass tests/test_base.py::TestSubclassTrafaret::test_repr tests/test_base.py::TestOnErrorTrafaret::test_on_error tests/test_base.py::TestOnErrorTrafaret::test_on_error_ensured_trafaret tests/test_base.py::TestOnErrorTrafaret::test_on_error_data_error tests/test_base.py::test_with_repr tests/test_base.py::TestGuard::test_keywords_only tests/test_base.py::TestGuard::test_class_method tests/test_base.py::TestGuard::test_args_checks tests/test_base.py::test_ignore tests/test_base.py::test_deprecated
trafaret/codes.py trafaret/base.py trafaret/__init__.py
trafaret/codes.py trafaret/base.py trafaret/__init__.py